File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception Handling" Watch "Exception Handling" New topic

Exception Handling

Ann Sebastian
Ranch Hand

Joined: Sep 21, 2005
Posts: 37

Options are...

A. An exception is thrown and the exception message thrown from first catch is diplayed with the exception stack trace.
B. An exception is thrown and the exception message thrown from second catch is diplayed with the exception stack trace.
C. Prints nothing.

D. Compilation error.

E. Prints i=? where ? stands for the generated random value.


Surprisingly ...the answer is C

Error stack trace is not thrown because of finally
I guess it should atleast throw exception...

Pls throw some insight if my understanding is wrong
Krishna Latha Grandhi
Ranch Hand

Joined: Nov 08, 2005
Posts: 110
Hi friend,

In catch Block if any exceptions are raised again or it return call to the called method. Before handling the exception or before returning value it will execute finally block.

But in case finally block there is no control transfers like this. you returned value of type void. If you have any return statements or System.exit()in finally block,if any exception raising and return statements are present in catch block, then they were discarded.

niraj gurjar

Joined: Nov 20, 2004
Posts: 4
Since the finally block of a try-catch-finally clause is always executed, even if a break or return statement is executed in the try block, the finally block can actually override the request to break or return.

The finally block can decide not to break or return or even change the return value by executing its own return statement.

here return statement in finally overrides return statemetn of catch block

Niraj Gurjar
I agree. Here's the link:
subject: Exception Handling
It's not a secret anymore!