• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Exception Debug issue for return

 
Ranch Hand
Posts: 423
  • 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.

 
Greenhorn
Posts: 20
  • 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.
 
Ranch Hand
Posts: 423
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your explanation is much better than documentation..Thanks Ireneusz and Jigar.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!