All Products
Search
Document Center

Function Compute:Error handling

Last Updated:Feb 02, 2024

This topic describes how to handle errors in the PHP runtime environment.

If an error occurs during the execution of a PHP function, Function Compute captures the error and returns the error information. In the following sample code, the error information oops is returned:

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

When you invoke the function, the system may return the following response:

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

If an error occurs, the HTTP header in the response to the function invocation contains X-Fc-Error-Type: UnhandledInvocationError. For information about the error types of Function Compute, see the "Error handling" section of the Basics topic.