PHP8 Exception

2023-08-21 11:21 更新

(PHP 5, PHP 7, PHP 8)

簡介

Exception是所有用戶級異常的基類。

類摘要

class Exception implements Throwable {
/* 屬性 */
protected string $message = "";
private string $string = "";
protected int $code;
protected string $file = "";
protected int $line;
private array $trace = [];
private ?Throwable $previous = null;
/* 方法 */
public __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
final public getMessage(): string
final public getPrevious(): ?Throwable
final public getCode(): int
final public getFile(): string
final public getLine(): int
final public getTrace(): array
final public getTraceAsString(): string
public __toString(): string
private __clone(): void
}

屬性

message

異常消息內容

code

異常代碼

file

拋出異常的文件名

line

拋出異常在該文件中的行號

previous

之前拋出的異常

string

字符串形式的堆棧跟蹤

trace

數(shù)組形式的堆棧跟蹤

目錄

  • Exception::__construct — 異常構造函數(shù)
  • Exception::getMessage — 獲取異常消息內容
  • Exception::getPrevious — 返回前一個 Throwable
  • Exception::getCode — 獲取異常代碼
  • Exception::getFile — 創(chuàng)建異常時的程序文件名稱
  • Exception::getLine — 獲取創(chuàng)建的異常所在文件中的行號
  • Exception::getTrace — 獲取異常追蹤信息
  • Exception::getTraceAsString — 獲取字符串類型的異常追蹤信息
  • Exception::__toString — 將異常對象轉換為字符串
  • Exception::__clone — 異??寺?/li>


以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號