PHP8 Throwable

2023-08-21 15:08 更新

(PHP 7, PHP 8)

簡(jiǎn)介

Throwable 是能被 throw 語(yǔ)句拋出的最基本的接口(interface),包含了 Error 和 Exception 。

注意:PHP 類(lèi)無(wú)法直接實(shí)現(xiàn) (implement) Throwable 接口,而應(yīng)當(dāng)去繼承 Exception。

接口摘要

class Throwable extends Stringable {
/* 方法 */
public getMessage(): string
public getCode(): int
public getFile(): string
public getLine(): int
public getTrace(): array
public getTraceAsString(): string
public getPrevious(): ?Throwable
public __toString(): string
/* 繼承的方法 */
public Stringable::__toString(): string
}

更新日志

版本 說(shuō)明
8.0.0 現(xiàn)在 Throwable 實(shí)現(xiàn)了 Stringable。

目錄

  • Throwable::getMessage — 獲取信息
  • Throwable::getCode — 獲取異常代碼
  • Throwable::getFile — 獲取創(chuàng)建對(duì)象的文件
  • Throwable::getLine — 獲取初始化對(duì)象時(shí)候的行號(hào)
  • Throwable::getTrace — 獲取堆棧蹤跡(Stack Trace)
  • Throwable::getTraceAsString — 以 string 形式獲取堆棧蹤跡
  • Throwable::getPrevious — 返回先前的 Throwable
  • Throwable::__toString — 獲取 Throwable 對(duì)象 string 形式的表達(dá)


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)