note 129177 added to language.exceptions

From: Date: Fri, 19 Jan 2024 08:24:31 +0000
Subject: note 129177 added to language.exceptions
Groups: php.notes 
Request: Send a blank email to php-notes+get-221131@lists.php.net to get a copy of this message
As noted elsewhere, throwing an exception from the finally block will replace a previously thrown exception. But the original exception is magically available from the new exception's getPrevious(). <?php try { try { throw new RuntimeException('Exception A'); } finally { throw new RuntimeException('Exception B'); } } catch (Throwable $exception) { echo $exception->getMessage(), "\n"; // 'previous' is magically available! echo $exception->getPrevious()->getMessage(), "\n"; } ?> Will print: Exception B Exception A ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 85.195.255.242) ---- Manual Page -- https://php.net/manual/en/language.exceptions.php Edit -- https://main.php.net/note/edit/129177 Del: integrated -- https://main.php.net/note/delete/129177/integrated Del: useless -- https://main.php.net/note/delete/129177/useless Del: bad code -- https://main.php.net/note/delete/129177/bad+code Del: spam -- https://main.php.net/note/delete/129177/spam Del: non-english -- https://main.php.net/note/delete/129177/non-english Del: in docs -- https://main.php.net/note/delete/129177/in+docs Del: other reasons-- https://main.php.net/note/delete/129177 Reject -- https://main.php.net/note/reject/129177 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221131) next »