public class MyExceptionHandle {
public static void main(String a[]){
try{
for(int i=5;i>=0;i--){
System.out.println(10/i);
}
} catch(Exception ex){
System.out.println("Exception Message: "+ex.getMessage());
ex.printStackTrace();
}
System.out.println("After for loop...");
}
}
Output:
2
2
3
5
10
Exception Message: / by zero
java.lang.ArithmeticException: / by zero
at com.myjava.exceptions.MyExceptionHandle.main(MyExceptionHandle.java:12)
After for loop...
No comments:
Post a Comment