/** * @author lautturi.com * Java example: Exception handling using try...catch */ import java.util.*; public class Lautturi { public static void main(String[] args) { try { // divided by 0 will trigger an exception int divideByZero = 10 / 0; System.out.println(divideByZero); } catch (ArithmeticException e) { System.out.println("ArithmeticException => " + e.getMessage()); } } }
output:
ArithmeticException => / by zero