PHP Exception getPrevious() 方法
示例
獲取關於前一個異常的資訊
<?php
try {
try {
throw new Exception("發生了一個錯誤", 1);
} catch(Exception $e1) {
throw new Exception("發生了另一個錯誤", 2, $e1);
}
} catch (Exception $e2) {
echo $previous = $e2->getPrevious();
echo $previous->getMessage();
}
?>
自己動手試一試 »
定義和用法
如果異常是由另一個異常觸發的,則 getPrevious()
方法將返回另一個異常。否則,它將返回 null。
語法
$exception->getPrevious()
技術詳情
返回值 | 返回一個整數 |
---|
相關頁面
在我們的 PHP Exceptions 章節 中閱讀更多關於 Exceptions 的資訊。
❮ PHP Exception 參考