|
|

The Catch or Specify Requirement:
Valid Java programming language code must honor the Catch or Specify Requirement. This means that code that might throw certain exceptions must be enclosed by either of the following:
A try statement that catches the exception. The try must provide a handler for the exception
A method that specifies that it can throw the exception. The method must provide a throws clause that lists the exception
Can someone show me the block of code which explains the try statement which catches the exception.
Also the method that specifies that it can throw the exception, this would be much appreciated![]()

So thats block of code there is a try statement?
And thank you for taking the time to post itrepped.
What the above method does is throw an Exception if the Object var is null, otherwise it will be printed to System.outCode:void test() throws Exception { if(var == null) throw new Exception("Var is null"); System.out.println(var); }
To catch any errors thrown by this method you can do this:
what this will do is if test() throws an exception, the error message from the exception is printed to console.Code:try { test(); } catch(Exception e) { System.out.println(e.getMessage()); }

Thank you very much king i now understand
repped![]()

nvm.
| « PageViewer Release.. | C window info. » |
| Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |