-1

i was reading about Throwable class from https://docs.oracle.com/javase/7/docs/api/java/lang/Throwable.html but i was not able to understand the chained exception facility. so somebody can please help me in this.

GURMEET SINGH
  • 111
  • 14

1 Answers1

3

As Oracle doc says

Chained Exception Facility

It is common for Java code to catch one exception and throw another

And an example here from TutorialsPoint:

public class Main{
   public static void main (String args[])throws Exception { 
      int n = 20, result = 0;
      try { 
         result = n/0;
         System.out.println("The result is"+result);
      } catch(ArithmeticException ex) { 
         System.out.println ("Arithmetic exception occoured: "+ex);
         try { 
            throw new NumberFormatException(ex);
         } catch(NumberFormatException ex1) {
            System.out.println ("Chained exception thrown manually : "+ex1);
         }
      }
   }
}
Flown
  • 11,480
  • 3
  • 45
  • 62
Fady Saad
  • 1,169
  • 8
  • 13