use try catch to handle exception in java
/**
* @author lautturi.com
* Java example: Java Exception Example
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
try {
int divideByZero = 5 / 0;
} catch (Exception e) {
System.out.println("exception occurs");
System.out.println(e);
System.out.println("exception message " + e.getMessage());
}
}
}
output:
exception occurs java.lang.ArithmeticException: / by zero exception message / by zero