---
title: "Handling Exceptions"
slug: "handling-exceptions"
updated: 2024-10-09T10:13:35Z
published: 2024-10-09T10:13:35Z
canonical: "docs.onespan.com/handling-exceptions"
---

> ## Documentation Index
> Fetch the complete documentation index at: https://docs.onespan.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Handling Exceptions

[Java SDK](/v1/docs/handling-exceptions#java-sdk) [.NET SDK](/v1/docs/handling-exceptions#net-sdk)

## Java SDK

To download the full code sample see our [Code Share](https://github.com/eSignLive/esl.sdk.java/blob/master/sdk/src/main/java/com/silanis/esl/sdk/examples/ExceptionHandlingExample.java) site.

The following exception types exist in OneSpan Sign:

- 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 sample illustrates how to differentiate between these exception types and how to gain access to the underlying server response if an EslServerException is thrown:

```java
try {
      signer = signerBuilder.build();
} catch( EslException eslException ) {
      System.out.println( eslException.getLocalizedMessage() );
      return;
}
try {
     eslClient.getPackageService().addSigner( new PackageId( "myPackageId" ), signer);
} catch( EslServerException eslServerException ) {
      // The request was refused by the server for some reason...
      System.out.println(eslServerException.getLocalizedMessage());
      System.out.println(eslServerException.getServerError().getCode());
      System.out.println(eslServerException.getServerError().getMessage());
      System.out.println(eslServerException.getServerError().getTechnical());
      return;
} catch( EslException eslException ) {
      System.out.println( eslException.getLocalizedMessage() );
      return;
}
```

## .NET SDK

To download the full code sample see our [Code Share](https://github.com/eSignLive/esl.sdk.net/blob/master/sdk/SDK.Examples/src/ExceptionHandlingExample.cs) site.

The following exception types exist in OneSpan Sign:

- 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 sample illustrates how to differentiate between these exception types and how to gain access to the underlying server response if an EslServerException is thrown:

```csharp
try
{
    signer = signerBuilder.Build();
}
catch (EslException eslException)
{
     Console.Out.WriteLine(eslException.Message);
     return;
}
try
{
     eslClient.PackageService.AddSigner(new PackageId("myPackageId"),signer);                                
}
catch (EslServerException eslServerException)
{
      Console.Out.WriteLine(eslServerException.Message);
      Console.Out.WriteLine(eslServerException.ServerError.Code);
      Console.Out.WriteLine(eslServerException.ServerError.Message);
      Console.Out.WriteLine(eslServerException.ServerError.Technical);
 }
catch (EslException eslException)
{
      Console.Out.WriteLine(eslException.Message);
      return;
}
```
