File size: 575 Bytes
c574d3a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
public class JavaExceptionExample {
public static void main(String args[]) {
try {
// code that may raise exception
int data = 100 / 0;
System.out.println("Value of data: " + data);
} catch (ArithmeticException e) {
System.out.println(e);
}
// rest code of the program
System.out.println("rest of the code...");
}
}
// try{
// code that may throw an exception
// }catch(Exception_class_Name ref){
// ...
// }
// try{
// code that may throw an exception
// }finally{
// ...
// } |