Skip to content

Latest commit

 

History

History
29 lines (24 loc) · 658 Bytes

0778.md

File metadata and controls

29 lines (24 loc) · 658 Bytes

Give the following code?

try {
   // ...
} catch (MyEx1 $e) {
    logError($e);
} catch (MyEx2 $e) {
    logError($e);
} catch (MyEx3 $e) {
    logError($e);
}

Since all "catch" blocks have the same code, how can you avoid duplication here?

  • A) "catch(MyEx1 | MyEx2 | MyEx3 $e)";
  • B) By replacing the "catch" blocks with one "finally" block;
  • C) By catching any like this: "catch(Exception $e)";
  • D) "catch(MyEx1, MyEx2, MyEx3 $e)";
Answer

Answer: A