• 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • 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....
 
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic