Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Nested try/catch block

 
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).]
 
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....
 
joke time: What is brown and sticky? ... ... ... A stick! Use it to beat this tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic