This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception Handling" Watch "Exception Handling" New topic
Author

Exception Handling

Arun Pai
Ranch Hand

Joined: Mar 11, 2002
Posts: 143
public class TestClass3
{
public static void main(String args[])
{
int k = 0;
try{
int i = 5/k;
}
catch (ArithmeticException e){
System.out.println("1");
//return;
}
catch (RuntimeException e){
System.out.println("2");
return ;
}
catch (Exception e){
System.out.println("3");
}
finally{
System.out.println("4");
}
System.out.println("5");
}
}
The output is 145, but if return is uncommented in catch the output is 14. can anyone explain the difference in output if Try/Catch returns.

-Arun
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
I've tried answering that question in this thread.
-anthony
Arun Pai
Ranch Hand

Joined: Mar 11, 2002
Posts: 143
Thanks Anthony.
-Arun
 
 
subject: Exception Handling
 
Similar Threads
Enthuware questions
unreachable code in 'finally'
Exceptions
Why is 5 getting printed here?
Weird Output !!