adsense


Showing posts with label JAVA EXAMPLES EXCEPTION HIERARCHIES. Show all posts
Showing posts with label JAVA EXAMPLES EXCEPTION HIERARCHIES. Show all posts

Thursday, 29 October 2015

JAVA EXAMPLES EXCEPTION HIERARCHIES PAGE 123

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES EXCEPTION HIERARCHIES





Java Examples - Exception Hierarchies


Problem Description:
How to handle the exception hierarchies?
Solution:
This example shows how to handle the exception hierarchies by extending Exception class ?
class Animal extends Exception {
}
class Mammel extends Animal {
}
public class Human {
   public static void main(String[] args) {
      try {
         throw new Mammel();
      }
      catch (Mammel m) {
         System.err.println("It is mammel");
      }
      catch (Annoyance a) {
         System.err.println("It is animal");
      }
   }
}
Result:
The above code sample will produce the following result.
It is mammel