|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-01-25 14:56 UTC] mimipim at abv dot bg
Description: ------------ https://3v4l.org/iA7rS Test script: --------------- <?php class TestException extends Exception{} try { throw new TestException(); } catch(TestException $e) { var_dump('catched TestException'); throw $e; } catch (Exception $e) { var_dump('catched exception'); } Expected result: ---------------- I am expecting to catch both exceptions but only the first is catched and than a fatal error occurs. Actual result: -------------- string(21) "catched TestException" Fatal error: Uncaught TestException in /in/iA7rS:6 Stack trace: #0 {main} thrown in /in/iA7rS on line 6 Process exited with code 255. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 15 04:00:02 2025 UTC |
I think you've misunderstood how try/catch blocks work. A catch block only catches exceptions from within the try block it is attached to. It does not catch exceptions from the other catch blocks. This is deliberate to allow 'recasting' some exceptions to other exception types. try { ... } catch (SpecificException $se) { throw new OtherException("this is a wrapped exception", $se); } catch (Exception $e) { throw $e; }