All Products
Document Center

Alibaba Cloud SDK:Handle an exception

Last Updated:May 23, 2023

This topic describes the exception types of the Classic SDK and how to handle an exception.

In the Classic SDK, exceptions are classified into two types: exceptions that occur on the server and exceptions that occur on the client. If a response contains ServerException, the exception occurs on the server. If a response contains ClientException, the exception occurs on the client. If an exception occurs and the server receives no requests, you cannot obtain the ID of the request that causes the exception. If the server receives the request that causes the exception, you can obtain the request ID. Then, you can use the request ID to ask Alibaba Cloud technical support for help.
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
try {
} catch (ClientException $e) {
    // Obtain the error message.
    echo $e->getErrorMessage();
} catch (ServerException $exception) {
    // Obtain the error code.
    // Obtain the request ID.
    // Obtain the error message.
    // Obtain the result object.
    // Obtain the response object.
    // Obtain the request object.