Catching a group of exceptions

  • 3
  • Locked
There are 3 exceptions that successively inherit Exception (Exception1 extends Exception, Exception2 extends Exception1, and Exception3 extends Exception2). In the program, you will find the public static void method1() throws Exception1, Exception2, Exception3 method. Task: write a catch block that will catch all three exceptions: Exception1, Exception2, and Exception3.
You can't complete this task, because you're not signed in.
Comments (3)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
OBINNA
Level 16 , Texas, United States
7 June 2021, 04:52
Because Exception 2 and Exception 3 inherits Exception 1 which in turn inherits the Exception class.. So Exception 1 catches all exceptions.
Mateo
Level 26 , Zagreb, Croatia
26 March 2019, 11:12
Solved it but can someone explain why
catch (Exception1 e){ }
catches all 3 thrown Exceptions?
Roman
Level 41
27 March 2019, 07:37
because inheritance )