PHP Exception getCode() Method
Example
Throw an exception and output its code:
<?php
try {
throw new Exception("An error occurred", 120);
}
catch(Exception $e) {
echo "Error code: " . $e->getCode();
}
?>
Try it Yourself »
Definition and Usage
The getCode()
method returns an integer which can be used to identify the exception.
Syntax
$exception->getCode()
Technical Details
Return Value: | Returns an integer |
---|
Related Pages
Read more about Exceptions in our PHP Exceptions Chapter.
❮ PHP Exception Reference