DEV Community

Cover image for EXCEPTION HANDLING
Vinoth Kumar
Vinoth Kumar

Posted on

EXCEPTION HANDLING

EXCEPTION HANDLING IN JAVA :

A mechanism used to handle exceptional conditions that occur during program execution. It helps prevent the program from terminating unexpectedly and allows developers to provide appropriate recovery or error-handling logic.

TYPES OF EXCEPTION HANDLING :

  1. User-Defined Exception.
  2. Built-in Exception.

USER-DEFINED EXCEPTION :
In Java are not able to describe a certain situation. In such cases, users can also create exceptions, which are called as user-defined Exceptions.

Basic try-catch :

The try block contains code that might throw an exception,and catch block handles the exception if it occurs.

BUILD-IN EXCEPTION :

These are pre-defined exception classes provided by Java to handle common errors during program execution. There are two type of built-in exception in java.

Checked Exception :
These exceptions are checked at compile time, forcing the programmer to handle them explicitly.

Unchecked Exception :
These exceptions are checked at runtime and do not require explicit handling at compile time.

Top comments (0)