我被以下代码困惑:
原文链接:https://www.f2er.com/php/131320.htmlclass MyException extends Exception {} class AnotherException extends MyException {} class Foo { public function something() { print "throwing AnotherException\n"; throw new AnotherException(); } public function somethingElse() { print "throwing MyException\n"; throw new MyException(); } } $a = new Foo(); try { try { $a->something(); } catch(AnotherException $e) { print "caught AnotherException\n"; $a->somethingElse(); } catch(MyException $e) { print "caught MyException\n"; } } catch(Exception $e) { print "caught Exception\n"; }
我会期望这样输出:
throwing AnotherException caught AnotherException throwing MyException caught MyException
而是输出:
throwing AnotherException caught AnotherException throwing MyException caught Exception
有人可以解释为什么它“跳过”catch(MyException $e)?
谢谢.