PHP 异常与错误 —— InvalidArgumentException

InvalidArgumentException

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

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

当参数不是预期的类型时,抛出 InvalidArgumentException 。继承 LogicException ,继承 Exception , PHP 7 引用接口 Throwable 。

 

class InvalidArgumentException extends LogicException 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 ) // 尝试克隆异常,将导致一个致命错误

}

 

posted @ 2018-07-17 17:43  小胖暖她爹  阅读(18702)  评论(0编辑  收藏  举报