All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Exception Hierarchy In Java

Last Updated : Mar 11, 2024

Exception Hierarchy In Java

In this article we will show you the solution of exception hierarchy in java, Java has been around for a long time in the development world. Although several both these languages with far superior features have captured the market, Java is here to stay.

When learning Java, there is a lot to learn, including Java exceptions.

When a program executes, a Java exception causes a disruption in normal operation. It can happen at compile as well as run time and take many forms.

These exceptions are undesirable and have a basic hierarchy.

  • Exception in Java are even further classified into two types:
  • Checked exceptions are also referred to as compile-time exceptions.
  • A runtime exception is an unchecked exception.

One thing to keep in mind at this point would be that unchecked Exceptions all are subclasses of a RuntimeException class.

Later in this article, we'll go over did check and unchecked exceptions in greater detail.

But first, so there is no confusion, let's look at how Errors, as well as Exceptions, differ in one‘s operation.

The exception hierarchy inside the programming java begins with the Throwable class, which also descends from of the Object class and is its direct subclass.

The exception is a class that represents all exceptions. This Throwable class is further subdivided into Error and Exception.

The Exception class contains all the Exclusions that you might encounter while programming in Java.

Examples of such Exclusions include NullPointerException, ClassNotFoundException, IllegalArgumentException, and many others.

The Error class, on the other hand, handles more serious problems in one’s Java program architecture and isn't handled inside the application code.

InternalError, AssertionError, OutOfMemoryError, and other errors in Java are examples.

This same Object class is indeed the parent class of any and all Java classes and all the errors as well as Exceptions objects are inherited either by throwable class.

Errors and Exceptions are subclasses of the throwable class.

Step By Step Guide On Exception Hierarchy In Java :-

import java.io.*;
class Talkers Code{
 static void check (int n)
 {
     if (n == 1) {
         return;
     }
     check(n + 2);
 }
 Public static void main(String[] args) { check(6); }
}
  1. First, we make an import function called java.io.*.
  2. The following step involves creating a class named TalkersCode.
  3. The following step is to write a static function.
  4. then we create if statement.
  5. As a result, as a string argument, a public static void main has been created.
  6. We then end the program.

Conclusion :-

The exception hierarchy inside the programming java begins with the Throwable class, which also descends from of the Object class and is its direct subclass.

The exception is a class that represents all exceptions. This Throwable class is further subdivided into Error and Exception.

I hope this article on exception hierarchy in java helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Riya

A recent graduate with a Bachelor of Technology (B.Tech) in Computer Science from India. She is passionate about leveraging technology to solve real-world problems. With a strong foundation and experience in programming languages such as Python, Django, HTML, CSS, and JavaScript, java, php and have honed her skills through hands-on projects and coursework.

Follow Riya On Linkedin 🡪