错误处理
 
                  更新时间 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[] | 异常堆栈。 | 
