PHP Throwable接口

PHPz
PHPz 转载
2023-09-12 21:42:02 940浏览

PHP Throwable接口

简介

在 PHP 7 中,Throwable 接口充当任何可以作为 throw 语句参数的对象的基础,包括错误异常。 Error 和 Exception 类(分别派生预定义的和用户定义的错误和异常类)都实现 Throwable 接口。 Throwable 接口中定义了以下抽象方法 -

语法

Throwable {
   /* Methods */
   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 ) − string -> 获取抛出对象的字符串表示形式

以上就是PHP Throwable接口的详细内容,更多请关注php中文网其它相关文章!

声明:本文转载于:tutorialspoint,如有侵犯,请联系admin@php.cn删除