File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Debug issue for return Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception Debug issue for return" Watch "Exception Debug issue for return" New topic
Author

Exception Debug issue for return

Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Hi, In the first example, control is not coming to return statement after finally block. But, In second example, control is coming to return statement as expected after finally block execution. Please advice if you know the reason.


OCPJP 6.0-81% | Preparing for OCWCD
http://www.certpal.com/blogs/cert-articles | http://sites.google.com/site/mostlyjava/scwcd |
Jigar Gandhi
Greenhorn

Joined: May 13, 2008
Posts: 20
In the first statement there is a DivideByZero Error so both catch and finally block gets executed.
while in the second case there is no exception so it returns and then executes the finally.
Finally is a block that is executed compulsarily after the try block.
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Hi,
in the first example an exception occurs at line 05 (Divide by zero).
In case of exception Java stops executing the try block
- the remaining instructions in the try block (after the point where exception has ocurred) are simply skipped - Java does not execute them.
Java executes an appriotriate catch block (if any), then finally block (if exists), and finishes executing the whole try-catch-finally block.
Java does not retry the instruction where exception has ocurred not continue executing instructions that are below this point.
Read java tutorial to refresh basics about exception handling:
http://download.oracle.com/javase/tutorial/essential/exceptions/putItTogether.html
Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Your explanation is much better than documentation..Thanks Ireneusz and Jigar.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception Debug issue for return