Java SDK
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 ofEslException
. AnEslServerException
is thrown when the server returns unexpected code from a request. TheEslServerException
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 ); }