Question:What is the output of the following code?
<?php

class MyException extends Exception {}
class AnotherException extends MyException {}

class Foo {
  public function something() {
    throw new AnotherException();
  }
  public function somethingElse() {
    throw new MyException();
  }
}

$a = new Foo();

try {
  try {
    $a->something();	
  } catch(AnotherException $e) {
    $a->somethingElse();	
  } catch(MyException $e) {
    print "Caught Exception";
  }
} catch(Exception $e) {
  print "Didn't catch the Exception!";
}

?>
 

A "Caught Exception" followed by "Didn't catch the Exception!" 

B A fatal error for an uncaught exception 

C "Didn't catch the Exception!" 

D "Didn't catch the Exception!" followed by a fatal error 

E "Caught Exception" 

+ Answer
+ Report
Total Preview: 755

Copyright © 2024. Powered by Intellect Software Ltd