PHP 异常与错误 —— RuntimeException

RuntimeException

官方文档地址: http://php.net/manual/en/class.runtimeexception.php

PHP 支持版本: 5 >=5.1, 7

错误异常。继承 Exception , PHP 7 引用接口 Throwable 。

class RuntimeException extends Exception implements Throwable { // PHP 7 支持 Throwable 接口

  /* 继承属性 */
  protected string $message; // 异常信息
  
  protected int $code; // 错误代码
  
  protected string $file; // 出错文件
  
  protected int $line; // 出错行号
  
  
   /* 方法 */
  public __construct ([ string $message = "" [, int $code = 0 [, Exception $previous = NULL ]]] ) // 构造一个异常
  
  public __construct ([ string $message = "" [, int $code = 0 [, Throwable $previous = NULL ]]] ) // PHP 7
  
  /* 继承方法 */
  final public string Exception::getMessage ( void ) // 获取抛出的消息内容

  final public Throwable Exception::getPrevious ( void ) // 返回上一个 Throwable

  final public mixed Exception::getCode ( void ) // 获取抛出的错误代码

  final public string Exception::getFile ( void ) // 获取产生异常的文件名

  final public int Exception::getLine ( void ) // 获取相关行号

  final public array Exception::getTrace ( void ) // 获取追踪信息,返回数组形式

  final public string Exception::getTraceAsString ( void ) // 获取追踪信息,返回字符串形式

  public string Exception::__toString ( void ) // 抛出的对象以字符串形式返回,可以用 echo 打印相应结果

  final private void Exception::__clone ( void ) // 尝试克隆异常,将导致一个致命错误

}

猜你喜欢

转载自www.cnblogs.com/wengyingfeng/p/9337739.html