錯誤處理
更新時間 2024-12-10 11:41:27
最近更新時間: 2024-12-10 11:41:27
分享文章
本文介紹PHP運行環境的錯誤處理。
如果函數在執行過程中拋出異常,那么會被函數計算捕獲并返回異常信息。
如下示例代碼中,簡單拋出了一個異常:
<?php
function handler($event, $context) {
throw new Exception("something wrong");
}
函數被執行后函數計算會返回如下異常信息:
{
"errorMessage": "something wrong",
"errorType": "Exception",
"stackTrace": {
"file": "\/code\/index.php",
"line": 4,
"traceString": ""
}
}
異常信息包含如下三個字段:
| 字段 | 類型 | 解釋說明 |
|---|---|---|
| errorMessage | string | 異常信息。 |
| errorType | string | 異常類型。 |
| stackTrace | string[] | 異常堆棧。 |