Php/docs/exception.getcode

来自菜鸟教程
跳转至:导航、​搜索

Exception::getCode

(PHP 5, PHP 7, PHP 8)

Exception::getCode获取异常代码


说明

final public Exception::getCode ( ) : int

返回异常代码。


参数

此函数没有参数。


返回值

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


范例

Example #1 Exception::getCode()示例

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

以上例程的输出类似于:


The exception code is: 30

参见

  • Throwable::getCode()