Exception::getCode
PHP function
Edit on GitHub ✎
(PHP 5, PHP 7, PHP 8)
Gets the Exception code
Description
Exception::getCode(): int
Returns the Exception code.
Parameters Parameters
Return Values
Returns the exception code as int in Exception but possibly as other type in Exception descendants (for example as string in PDOException).
Examples
Exception::getCode() example
php
<?php
try {
throw new Exception("Some error message", 30);
} catch(Exception $e) {
echo "The exception code is: " . $e->getCode();
}
?>The above example will output something similar to:
output
The exception code is: 30See Also
Throwable::getCode