Exception Handling in Java: Types, Custom Exceptions, and Hierarchy Rules

FullStackTips
5 min readSep 5, 2023
Java exception types (Image Credit: GeeksforGeeks)

Exception handling is a fundamental concept in Java programming that allows you to manage and respond to errors gracefully. In this blog story we’ll dive into Java exceptions. We’ll explore the various types of exceptions, discuss when and why they occur, and learn how to create custom exceptions tailored to your specific application needs. Additionally, we’ll discuss the rules governing the exception hierarchy in the context of method overriding.

Types of Exceptions in Java

Java exceptions are categorized into two main types:

  1. Checked exceptions
  2. Unchecked exceptions.
Throwable
|
├── Error
|
└── Exception
|
├── IOException
|
├── SQLException
|
├── RuntimeException
| |
| ├── NullPointerException
| |
| ├── ArrayIndexOutOfBoundsException
| |
| └── ArithmeticException
|
└── ... (other subclasses of Exception)

As you in above exception hierarchy tree, the Throwable is the root class.

Exception: This is the base class for all checked exceptions.

RuntimeException: This is the base class for all unchecked exceptions.

Checked Exceptions:

--

--

FullStackTips

I am full stack developer with over 15 years of experience in various programming languages. https://medium.com/@fullstacktips/membership