Handling SDK Exceptions
  • 09 Oct 2024
  • 1 Minute to read
  • Dark
    Light
  • PDF

Handling SDK Exceptions

  • Dark
    Light
  • PDF

Article summary

When the SDK encounters a problem, it throws one of the following exception types:

  • EslException: This is a general exception. It includes a character string that indicates what failed.

  • EslServerException: This is a subclass of EslException. An EslServerException is thrown when the server returns unexpected code from a request. The EslServerException also contains the exact server response from the underlying API request.

The following code samples illustrate: (1) how to differentiate between those two exception types; (2) how to gain access to the underlying server response if an EslServerException is thrown:

try {
    PackageId packageId = eslClient.createPackageOneStep( superDuperPackage );
} catch (EslServerException serverException) {
    System.out.println( "The server could not complete the request." );
    System.out.println( serverException.getMessage() );
    System.out.println( "HTTP code: " + serverException.getServerError().getCode());
    System.out.println( "Server message: " + serverException.getServerError().getMessage());
} catch (EslException exception) {
    System.out.println( exception.getMessage() );
    System.out.println( exception.getCause().getMessage() );
}
try {
    PackageId packageId = eslClient.CreatePackageOneStep( superDuperPackage );
} catch (EslServerException serverException) {
    Console.Out.WriteLine( "The server could not complete the request." );
    Console.Out.WriteLine( serverException.Message );
    Console.Out.WriteLine( "HTTP code: " + serverException.ServerError.Code);
    Console.Out.WriteLine( "Server message: " + serverException.ServerError.Message);
} catch (EslException exception) {
    Console.Out.WriteLine( exception.Message );
    Console.Out.WriteLine( exception.InnerException.Message );
}


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.
ESC

Eddy AI, facilitating knowledge discovery through conversational intelligence