In PHP, Exception::getPrevious() returns the previous Throwable that was passed when the exception was created. If there was no previous exception, it returns null.
Use it for exception chaining: catch a low-level error, throw a higher-level Exception that wraps it, then later walk getPrevious() to see the full cause. The method is final.
Syntax
Call getPrevious() with the values you need. Start with this line.
PHP
$cause = $e->getPrevious();
Call
What it does
$e->getPrevious()
Returns the previous Throwable, or null if none was set.
$e->getPrevious()?->getMessage()
Safely reads the previous message when a previous exception exists.
while ($e = $e->getPrevious()) { ... }
Walks the whole chain of nested exceptions.
Pass the previous Throwable as the third argument to Exception::__construct(). getPrevious() is final and returns null when no chain was created.
Library declarations
PHP
final public Exception::getPrevious(): ?Throwable
Parameters
Parameter
Description
—
This method takes no parameters.
Return Value
Return Value
Description
?Throwable
The previous exception or error, or null if the constructor did not receive one.
PHP Examples
Example 1 — Wrap One Exception in Another
Catch a low-level Exception and rethrow a new one that keeps the original as previous.