Exception::getCode

(PHP 5, PHP 7, PHP 8)

Exception::getCode获取异常代码

说明

final public Exception::getCode(): int

返回异常代码。

参数

此函数没有参数。

返回值

Exception 返回整型(int)的异常代码,但在其他类中可能返回其他类型(比如在 PDOException 中返回 string)。

范例

示例 #1 Exception::getCode()示例

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

以上例程的输出类似于:

The exception code is: 30

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top