Bug #77520 [Opn->Nab]: Fatal error while catching re-thrown exception

From: Date: Fri, 25 Jan 2019 15:13:12 +0000
Subject: Bug #77520 [Opn->Nab]: Fatal error while catching re-thrown exception
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219203@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77520&edit=1 ID: 77520 Updated by: danack@php.net Reported by: mimipim at abv dot bg Summary: Fatal error while catching re-thrown exception -Status: Open +Status: Not a bug Type: Bug Package: Scripting Engine problem PHP Version: 7.2.14 Block user comment: N Private report: N New Comment: 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; } Previous Comments: ------------------------------------------------------------------------ [2019-01-25 14:56:11] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77520&edit=1

« previous php.bugs (#219203) next »