• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nested try/catch block

 
vadiraj vd
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
anil bisht
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is because the exception u are throwing in finnaly block is not caught....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic