update page now

Voting

: three minus two?
(Example: nine)

The Note You're Voting On

jlherren
2 years ago
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

<< Back to user notes page

To Top