Java Reference
In-Depth Information
22. The output would then be
First catch.
End of exercise.
23. The output would then be
Bingo!
End of exercise.
24. Trying
Starting sampleMethod.
Catching.
End program.
25. The output would then be
Trying
Starting sampleMethod.
Trying after call.
End program.
26. public static void doStuff( int n) throws Exception
{
if (n < 0)
throw new Exception("Negative number.");
}
27. If a method throws an exception and the exception is not caught inside the method,
then the method invocation ends immediately after the exception is thrown. If the
method invocation is inside a try block, then the exception is thrown to a match-
ing catch block, if there is one. If there is no catch block matching the exception,
then the method invocation ends as soon as that exception is thrown.
28. It might be caught in method B. If it is not caught in method B, it might
be caught in method C. If it is not caught in method C, it might be caught
outside of method C.
29. Yes, you can have a try block and corresponding catch blocks inside another
larger try block.
30. Yes, you can have a try block and corresponding catch blocks inside another
larger catch block.
31. In finally block.
Caught in main.
If the argument to sampleMethod is -42 instead of 42 , the output would be
Caught in sampleMethod.
In finally block.
After finally block.
Search WWH ::




Custom Search