handling:- During execution of a program some abnormal conditions (exception
situation) might be occurred.
If these abnormal condition will not be handle by the
program then abnormal conditions becomes error for the programs. Due to these errors program will be
terminated abruptly (sudden). If program handles these abnormal conditions becomes exceptions.In this case
program completes execution,this process is called exception handling.
Note:- Java is a robust programming language.Robust means
hard to break. This is because of following two features that JVM contains:-
Automatic exception handling
Automatic garbage collection
These are two main reason in java of program
Not handle abnormal condition
object:- When JVM incounters any abnormal condition,JVM converts
it into an exception.
In Java every exception is represented in the form of object.
In this object JVM store information about the exception
Source file of the method
These information is very useful for the programmer as
well as user.
After creating exception object JVM throws that object
towards the program to catch it,So that information stored in this object can
be show to user.
Catching exception:- This is responsibility of the
current program to catch the exception object that is thrown by JVM.
After catching exception object program will continue
execution.If program does not catch it then exception will be unhandled.
In the above case program will be terminated by JVM.
handler:- It is a code that is responsible to catch the exception
object.This code should be written by
Following three tools are given by language to write this
block:- These statements
of the method that might throw exception should be written inside this block.Every
try block must have atleast one finally catch block.
block:- This block is executed automatically when statement of
the ‘try block’ throws an exception.This block is responsible to store
reference of exception object into a variable.
public static void main(string  args)
System.out.println(“Arithmatic exception cought”);
System.out.println(“Array index exception cought”);
System.out.println(“Number format exception cought”);
Code written inside this block is always executed by the JVM,wheather an
exception thrown or not,wheather exception are handle.
You can also visit these related articles and blogs
Exception Handling in Java: try-catch statements
Exception Handling in Java: Asynchronous Exceptions and Important guidelines
What is Exception handling in java