All Products
Search
Document Center

Function Compute:Error handling

Last Updated:Feb 02, 2024

This topic describes how to handle errors in a Python runtime.

If an exception is thrown during function execution, Function Compute captures the exception and returns an error. Example:

def my_handler(event, context):
    raise Exception('something is wrong')

When sending the exception, Function Compute includes the X-Fc-Error-Type: UnhandledInvocationError HTTP header in the function response, and the HTTP request body contains the following information. For more information about error types in Function Compute, see Error handling.

{
  "errorMessage": "something is wrong",
  "errorType": "Exception",
  "stackTrace": [
    [
      "File \"/code/index.py\"",
      "line 2",
      "in my_handler",
      "raise Exception('something is wrong')"
    ]
  ]
}

The following table describes the fields in the error information.

Field

Type

Description

errorMessage

String

The error message.

errorType

String

The error type.

stackTrace

List

The error stack.