wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Nested try/catch block Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Nested try/catch block" Watch "Nested try/catch block" New topic
Author

Nested try/catch block

vadiraj vd
Ranch Hand

Joined: Dec 15, 2000
Posts: 68
Hi all,
Here's a code with nested try/catch block.
----------------
public class TryCatchDemo3
{
public static void main(String a[])
{
int i = 10,j = 0;
try
{
int k = i/j; // Arithmetic Exception here.
}catch(ArithmeticException r)
{
System.out.println("In outer catch block");
try
{
throw new InterruptedException("My Interruption"); // here new InterruptedException is thrown.
}catch(InterruptedException rr)
{
System.out.println("In inner catch block");
}
}finally
{
System.out.println("In finally block");
throw new InterruptedException("My Interruption");
}


}
}
-------------------
when I compile this, the compiler says you should expicitly catch the InterrupteedException(thrown in the inner catch block) or the main method should specify in its throws clause.
But I'm enclosing this
throw new InterruptedException("My Interruption");
in try/catch block which handles this exception.
Can someone help me?
regards,
----
vadiraj
[This message has been edited by vadiraj vd (edited December 19, 2000).]


Regards<BR>---------<BR>vadiraj<P><BR>*****************<BR>There's a lot of I in J.<BR>*****************
anil bisht
Ranch Hand

Joined: Nov 04, 2000
Posts: 81
it is because the exception u are throwing in finnaly block is not caught....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Nested try/catch block