File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes try catch exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "try catch exception handling" Watch "try catch exception handling" New topic

try catch exception handling

Jay Damon
Ranch Hand

Joined: Jul 31, 2001
Posts: 282
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

Joined: Apr 08, 2002
Posts: 16
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

Joined: Jan 30, 2000
Posts: 18671
1) yes
2) yes
3) yes

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: try catch exception handling
It's not a secret anymore!