Exception Handling-
Exception is an abnormal condition which is interrupt normal flow of program.
Exception is a class coming from java.lang package, And Throwable is a immediate parent class of Exception.
In Java 2 types of Exception
A. Checked [Compile Time] Exception-
- Those exceptions that are checked at compile-time also known as checked exceptions.
- The program will not compile if they are not handled.
- They are child classes of Exception except for RuntimeException.
Example: IOException, SQLException, etc.
B. Unchecked [Run Time] Exception-
- Those exceptions that are checked at runtime also known as unchecked exceptions.
- They give runtime errors if not handled explicitly.
- They are child classes of RuntimeException.
Example: ArithmeticException, NullPointerException, etc.
There are 5 blocks for Exception Handling-
- Try- Exceptional code will add in try block
- Catch- It is used for catch the Exception
- Throw- It is user defined Exception
- Throws- It is system generated Exception
- Finally- It always execute