/** * @author lautturi.com * Java example: catch Multiple Exceptions in java */ import java.util.*; public class Lautturi { public static void main(String[] args) { try { int array[] = new int[3]; array[5] = 12/2; // array[5] = 12/0; } catch (ArithmeticException e) { System.out.println(e); } catch (ArrayIndexOutOfBoundsException e) { System.out.println(e); } } }
output:
java.lang.ArithmeticException: / by zero java.lang.ArrayIndexOutOfBoundsException: 5