File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

try catch exception handling

 
Jay Damon
Ranch Hand
Posts: 282
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have encountered some code where an exception is thrown in the try{} block, is caught and is in the process of being handled by the catch{} block when another exception occurs.
In this code, once the second exception occurs in the catch{} block, it proceeds directly to the finally{} block (of the first exception) with no indication that a second exception ever occurred.
I was only able to deduce what was happening by stepping thru the code with a debugger.
My questions are:
1) Is this correct exception handling behavior?
2) Should a second exception be thrown?
3) And, if a second exception should be thrown, should the finally{} block for the first exception be executed?
 
Braj Prasad
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would need to handle the exception being thrown in the catch block with its own try/catch block, and do what you want to, before the execution is transfered to the finally block.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) yes
2) yes
3) yes
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic