PHP Throwable 介面


引言

在 PHP 7 中,Throwable 介面作為任何可作為 throw 語句引數的物件的基礎,包括 ErrorException。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 -> 獲取丟擲物件的字串表示形式

更新於: 2020年9月21日

431 次瀏覽

開始你的 職業生涯

完成課程即可獲得認證

開始學習
廣告
© . All rights reserved.