错误处理 本文介绍C运行环境的错误处理。 如果函数在执行过程中抛出异常,那么会被函数计算捕获并返回异常信息。 如下示例代码中,简单抛出了一个异常: csharp using System; using System.IO; using System.Text; using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Serverless.Cf; namespace Example { public class Hello { public async Task Handler(Stream input, ICfContext context) { throw new Exception("something wrong"); } static void Main(string[] args) { } } } 函数被执行后函数计算会返回如下异常信息: json { "errorMessage": "something wrong", "errorType": "Exception", "stackTrace": [ " at Example.Hello.Handler(Stream input, ICfContext context) in XXXHelloAppProgram.cs:line 15", ... ] } 异常信息字段说明: 字段 类型 解释说明 errorMessage string 异常信息。 errorType string 异常类型。 stackTrace string[] 异常堆栈。