All Products
Search
Document Center

Function Compute:Error handling

Last Updated:Feb 02, 2024

This topic describes the error types and error information in the Java runtime environment.

Error types

  • If an error occurs during the execution of a function, Function Compute captures the error and returns the error information.

    The following sample code provides an example:

    package example;
    
    import com.aliyun.fc.runtime.Context;
    import com.aliyun.fc.runtime.StreamRequestHandler;
    
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    
    public class HelloFC implements StreamRequestHandler {
    
        @Override
        public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
            throw new IOException("oops");
        }
    } 

    When the function is invoked, the following response is returned:

    {
      "errorMessage" : "oops",
      "errorType" : "java.io.IOException",
      "errorCause" : "oops",
      "stackTrace" : [ "example.HelloFC.handleRequest(HelloFC.java:15)" ]
    }
  • If your function proactively exits during running, the system returns a general error message.

    The following sample code provides an example:

    package example;
    
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    
    import com.aliyun.fc.runtime.Context;
    import com.aliyun.fc.runtime.StreamRequestHandler;
    
    public class App implements StreamRequestHandler {
    
        @Override
        public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
            System.exit(-1);
        }
    }

    When the function is invoked, the following response is returned:

    {
      errorMessage: 'Process exited unexpectedly before completing request (duration: 43ms, maxMemoryUsage: 65MB)'
    }

Error information

The following table describe the fields that are included in error information.

Field

Type

Description

errorMessage

String

The error message.

errorType

String

The error type.

stackTrace

List

The error stack.

For more information, see Basics.