Java Examples - Exception Hierarchies

Problem Description

How to handle the exception hierarchies ?

Here is the sample diagram of Exception Hierarchies


This example shows how to handle the exception hierarchies by extending Exception class ?

Live Demo
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");


The above code sample will produce the following result.

It is mammel