|
hi, A java exception is an object that describes an exceptional condition that has occured in a piece of code.When exceptional condition arises, an object representing that exception is created and 'thrown' in the method that caused the error. and the exception 'caught' and processed.
For example we go throw divide-by-zero error. when the java run-time system detects the attampt to dicide by zero, then it constructs a exception object and then throws this exception. it stops the excution bcoz exception is raised so to continue the excution we caught by an exception handler as follows.
class A{
public static void main(string s[]){
int a=0;
int b=10;
try{
int c=b/a;
System.out.println("We'll not be printed');
}catch(ArithmeticException e){
System.out.println("Divide by zero");
}
System.out.println("after the try-catch block");
}
}
|