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 ) // 嘗試克隆異常,將導致一個致命錯誤

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM