Example
Throw an exception and output its code:
html
<?php
try {
throw new Exception("An error occurred", 120);
}
catch(Exception $e) {
echo "Error code: " . $e->getCode();
}
?>
Definition and Usage
The getCode() method returns an integer which can be used to identify the exception.
Syntax
text
$exception->getCode()
Technical Details
| Return Value: | Returns an integer |
|---|