Wednesday 3 August 2022

What is an Exception?

An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions.

Many different kinds of errors can cause exceptions: problems ranging from serious hardware errors, such as a hard disk crash, to simple programming errors, such as trying to access an out-of-bounds array element. When such an error occurs within a Java method, the method creates an exception object and hands it off to the runtime system. The exception object contains information about the exception including its type and the state of the program when the error occurred. The runtime system is then responsible for finding some code to handle the error. In terminology, creating an exception object and handing it to the runtime system is called throwing an exception.

Types of exceptions :

1. Checked exceptions
2. Unchecked exceptions

Examples of exceptions : 

The following are examples of exceptions:

1. ClassNotFoundException
2. IllegalStateException
3. IllegalArgumentException
4. NullPointerException
5. SQLException

0 comments:

Post a Comment

Please do not enter any spam link in the message box.