
- Example - Home
- Example - Environment
- Example - Strings
- Example - Arrays
- Example - Date & Time
- Example - Methods
- Example - Files
- Example - Directories
- Example - Exceptions
- Example - Data Structure
- Example - Collections
- Example - Networking
- Example - Threading
- Example - Applets
- Example - Simple GUI
- Example - JDBC
- Example - Regular Exp
- Example - Apache PDF Box
- Example - Apache POI PPT
- Example - Apache POI Excel
- Example - Apache POI Word
- Example - OpenCV
- Example - Apache Tika
- Example - iText
- Java Useful Resources
- Java - Quick Guide
- Java - Useful Resources
How to handle the exception hierarchies in Java
Problem Description
How to handle the exception hierarchies?
Here is the sample diagram of 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"); } } }
Result
The above code sample will produce the following result.
It is mammel
java_exceptions.htm
Advertisements