All Products
Search
Document Center

Function Compute:Error handling

Last Updated:Apr 01, 2026

If an error occurs during the execution of a PHP function, Function Compute captures the error and returns a structured error response. Use the response body and HTTP header together to identify the failure cause and decide on next steps.

How it works

The following example throws a standard PHP exception:

<?php
function handler($event, $context) {
  throw new Exception("oops");
}

When you invoke this function, Function Compute returns a JSON response similar to:

{
    "errorMessage": "oops",
    "errorType": "Exception",
    "stackTrace": {
        "file": "/code/index.php",
        "line": 3,
        "traceString": ""
    }
}

The response fields are:

FieldDescription
errorMessageThe exception message passed to the constructor
errorTypeThe PHP exception class name
stackTrace.fileThe file path where the exception was thrown
stackTrace.lineThe line number where the exception was thrown
stackTrace.traceStringA string representation of the stack trace

In addition to the response body, the HTTP response includes the header X-Fc-Error-Type: UnhandledInvocationError, which signals that the invocation failed due to an unhandled exception in your function code.

What to do when an error occurs

When you receive X-Fc-Error-Type: UnhandledInvocationError:

  1. Check errorMessage and errorType in the response body to identify the exception.

  2. Review the function logs for the full stack trace and runtime context.

What's next

  • For the full list of error types that Function Compute can return, see the Error handling section of the Basics topic.