PHP Throwable 接口
phpserver side programmingprogramming更新于 2025/8/19 4:37:17
简介
在 PHP 7 中,Throwable 接口作为任何可作为 throw 语句参数的对象的基础,包括 Error 和 Exception。Error 类和 Exception 类分别派生自预定义和用户定义的错误和异常类,它们都实现了 Throwable 接口。Throwable 接口中定义了以下抽象方法 −
语法
Throwable {
/* 方法 */
abstract public getMessage ( void ) : string
abstract public getCode ( void ) : int
abstract public getFile ( void ) : string
abstract public getLine ( void ) : int
abstract public getTrace ( void ) : array
abstract public getTraceAsString ( void ) : string
abstract public getPrevious ( void ) : Throwable
abstract public __toString ( void ) : string
}
方法
getMessage ( void ) − string -> 返回与抛出对象关联的消息。
getCode ( void ) − int ->返回与抛出对象关联的错误代码。
getFile ( void ) − string -> 获取创建抛出对象的文件的名称。
getLine ( void ) − int -> 返回实例化抛出对象的行号。
getTrace ( void ) − array -> 以数组形式返回堆栈跟踪信息。
getTraceAsString ( void ) − string -> 以字符串形式返回堆栈跟踪信息。
getPrevious ( void ) − Throwable -> 返回任何先前的 Throwable(作为 Exception::__construct() 的第三个参数提供)。
__toString ( void ) −字符串 -> 获取抛出对象的字符串表示形式

