dsa

Java Exceptions

In this tutorial, we will learn about exceptions in Java. We will cover errors, exceptions and different types of exceptions in Java.

An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception occurs the normal flow of the program is disrupted and the program/Application terminates abnormally, which is not recommended, therefore, these exceptions are to be handled.

Java Exception hierarchy

Here is a simplified diagram of the exception hierarchy in Java.

ExceptionHierarchy
ExceptionHierarchy

Error: An Error indicates serious problem that a reasonable application should not try to catch.
Exception: Exception indicates conditions that a reasonable application might try to catch.

Java Exception Types

The exception hierarchy also has two branches: RuntimeException and IOException.