Exception Handling:

Error: Irrecoverable thing in the program.We can't handle errors by using try,catch,finally blocks.
Exception: Abnormal termination of process.We can handle exceptions by using try,catch,finally blocks.
Try Statement executes block of code for specific reason.
Catch Statement caught the errors that are thrown inside try block.
Finally statement always execute after the try catch block and If the exception raised or not the code in the finally block will execute.
EX: connection closing statement.

Syntax:

try {
   //statements
}
catch(Exception Identifier) {
  //statements
}
finally {
  //statements
}

Example 1: Code:



Output:


Example 2:
code:



Output: