Yes, we can define one try block with multiple catch blocks in Java.
class TryWithMultipleCatch { public static void main(String args[]) { try{ int a[]=new int[5]; a[3]=10/0; System.out.println("First print statement in try block"); } catch(ArithmeticException e) { System.out.println("Warning: ArithmeticException"); } catch(ArrayIndexOutOfBoundsException e) { System.out.println("Warning: ArrayIndexOutOfBoundsException"); } catch(Exception e) { System.out.println("Warning: Some Other exception"); } System.out.println("Out of try-catch block"); } }
Warning: ArithmeticException Out of try-catch block