DEV Community

PRIYA K
PRIYA K

Posted on

Exception Hierarchy

java.lang
Class Exception

java.lang.Object
    ↳ java.lang.Throwable
          ↳ java.lang.Exception

All Implemented Interfaces:
    Serializable
Enter fullscreen mode Exit fullscreen mode

1.java.lang
This is the package name.
Exception class belongs to the java.lang package.

  1. Class Exception Exception is a class It is used for handling exceptions. Example:
catch(Exception e)
Enter fullscreen mode Exit fullscreen mode

Here Exception is a class object type.

  1. java.lang.Object This is the topmost parent class in Java. Every class in Java indirectly inherits from Object.

Example

class Student {
}

Enter fullscreen mode Exit fullscreen mode

Internally Java treats it as:

class Student extends Object {
}
Enter fullscreen mode Exit fullscreen mode

Object class provides methods like:
toString()
equals()
hashCode()

  1. java.lang.Throwable Throwable is the parent class for: Exceptions Errors

Hierarchy:
Object

Throwable

Exception

Why Throwable?
Because only objects derived from Throwable can be:
thrown
caught

using:
throw
try-catch

  1. java.lang.Exception
    Exception inherits from Throwable.
    It represents recoverable problems.
    Examples:
    divide by zero
    file not found
    invalid input

  2. Serializable
    Exception implements Serializable interface.

What is Serializable?
It allows objects to be converted into:
byte stream

so they can be
saved into file
sent through network
transferred between systems

Example Analogy
Serializable = packing object into a box

object converted into bytes
stored or transferred
later unpacked back

Complete Hierarchy Diagram
Object

Throwable

Exception

ArithmeticException

ArrayIndexOutOfBoundsException

Simple Analogy
Imagine family tree:
Object → Grandfather
Throwable → Father
Exception → Son
ArithmeticException → Grandson

Inheritance passes downward.

Exception is a class inside java.lang package that inherits from Throwable, which itself inherits from Object, and it implements the Serializable interface.

Top comments (0)