What is Exception | Exception Handling in Java | PLM Developer

An exception is an unwanted or unexpected event. It pretends the normal flow of the program instructions, which can cause the application to stop abnormally. The Exception may occur due to developing mistakes by writing code, or the user enters invalid data.

Exception Hierarchy:

Throwable class is the root class for all classes in Exception.

Errors

An Error is an irrecoverable condition such as Java virtual machine (JVM) running out of memory, memory leaks, stack overflow errors, infinite recursion, etc. Errors are usually beyond the programmer’s control, and we should not try to handle the mistakes.

Types of exceptions:

  1. Checked Exceptions (IOException)
  2. Un-Checked Exceptions (RuntimeException)

Checked Exceptions:

The compiler checks checked exceptions at the compile-time programmer is responsible for handling these exceptions. Checked exceptions is known as IOException.
Example:
FileNotFoundException usually occurs if we try to read data from any file which doesn’t exist or understanding with the wrong file name.

Un-Checked Exceptions:

The compile does not check Un-Checked exceptions. These exceptions have occurred at runtime, So they are also referred to as Runtime Exception.
Example:
ArrayIndexOutOfBoundsException
ArithmeticException
NullPointerException 

Exception Handling:

Exception handling is the way to handle run time exception and maintaining the normal flow of the application.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top