array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'exception.getcode.php', 1 => 'Exception::getCode', ), 'up' => array ( 0 => 'class.exception.php', 1 => 'Exception', ), 'prev' => array ( 0 => 'exception.getprevious.php', 1 => 'Exception::getPrevious', ), 'next' => array ( 0 => 'exception.getfile.php', 1 => 'Exception::getFile', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'language/predefined/exception/getcode.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5, PHP 7, PHP 8)
Exception::getCode — 获取异常代码
此函数没有参数。
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