獲取異常追蹤資訊

Exception::getTrace

(PHP 5, PHP 7, PHP 8)

Exception::getTrace獲取異常追蹤資訊

說明

final public Exception::getTrace(): array

返回異常追蹤資訊。

參數

此函式沒有參數。

返回值

返回包含異常追蹤資訊的陣列(array)。

範例

示例 #1 Exception::getTrace()示例

<?php
function test() {
 throw new 
Exception;
}

try {
 
test();
} catch(
Exception $e) {
 
var_dump($e->getTrace());
}
?>

以上例程的輸出類似於:

array(1) {
  [0]=>
  array(4) {
    ["file"]=>
    string(22) "/home/bjori/tmp/ex.php"
    ["line"]=>
    int(7)
    ["function"]=>
    string(4) "test"
    ["args"]=>
    array(0) {
    }
  }
}

參見

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *