1) Find the problem (Hit the exception)
2) Inform that an error has occurred (Throw the exception)
3) Receive the error information (Catch the exception)
4) Take necessary actions (Handle the exception)
Syntax of Exception Handling -
Try
{
Statement; //generates an exception
}
Catch
{
Statement; //process the exception
}
Private static void
int a=2, b=0, c=6;
try{
c=a/b;
system.out.println(c);
system.out.println(“Successful.”);
}
Catch(Arithmatic Exception e){
system.out.println(“Not successful.”);
}
}
}
[ OUTPUT : Not Successful. ]