PHP Exception getPrevious() Method
Example
Get information about a previous exception:
<?php
try {
try {
throw new Exception("An
error occurred", 1);
} catch(Exception $e1) {
throw new Exception("Another error occurred", 2, $e1);
}
}
catch (Exception $e2) {
echo $previous = $e2->getPrevious();
echo $previous->getMessage();
}
?>
Try it Yourself »
Definition and Usage
If the exception was triggered by another one, then the getPrevious()
method returns the other exception. Otherwise it returns null.
Syntax
$exception->getPrevious()
Technical Details
Return Value: | Returns an integer |
---|
Related Pages
Read more about Exceptions in our PHP Exceptions Chapter.
❮ PHP Exception Reference