wood burning stoves 2.0*
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception Handling" Watch "Exception Handling" New topic
Author

Exception Handling

Nina Binde
Ranch Hand

Joined: Sep 24, 2004
Posts: 85
If there is an exception caught in a method, will the statements after the try/catch block execute (I know finally block always executes) or will the control go back to the caller method?
If the exception is not caught, I know for sure that the control goes back to the caller at the point of exception and no more statements are executed after that.
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
yes
Nitin Bhagwat
Ranch Hand

Joined: Sep 09, 2004
Posts: 132
Nina, try this:

class ex
{
public static void main(String st[])
{
new ex1().exmethod1();
}
}

class ex1
{

void exmethod1()
{
try {
exmethod2();
} catch (Exception e)
{
System.out.println ("In Catch of Exception");
}

finally {
System.out.println ("In finally");
}

System.out.println ("After finally");
}

void exmethod2() throws Exception
{
throw new Exception();
}
}


"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
Nina Binde
Ranch Hand

Joined: Sep 24, 2004
Posts: 85
Thank you guys. Nitin, I tried the example and it is now clear to me. The question I asked was kind of stupid since if the statements after the try/catch block doesn't execute, then the purpose of the try/catch block is defeated!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception Handling