php8.5
Home/ Manual/ predefined / error/ Error::getCode

Error::getCode

PHP function Edit on GitHub ✎

(PHP 7, PHP 8)

Gets the error code

Description

Error::getCode(): int

Returns the error code.

Parameters Parameters

Return Values

Returns the error code as int

Examples

Error::getCode() example

php
<?php
try {
    throw new Error("Some error message", 30);
} catch(Error $e) {
    echo "The Error code is: " . $e->getCode();
}
?>

The above example will output something similar to:

output
The Error code is: 30

See Also

  • Throwable::getCode

Source: language/predefined/error/getcode.xml · from the official PHP manual (php/doc-en)