• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Debug issue for return

 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Jigar Gandhi
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 423
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 423
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your explanation is much better than documentation..Thanks Ireneusz and Jigar.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic