SDKs
...
Tutorials
Best Practices

Error Handling

7min

Error handling is an integral part of software development. This article provides effective ways to handle LicenseSpring errors and keep your application secure.

Prerequisites

  1. Completed the Getting Started Tutorial, specifically:
    • Initialized LicenseManager (or LicenseHandler) with your configuration using the appropriate settings.
    • Created a LicenseID using either LicenseID::fromKey or LicenseID::fromUser function, depending on the activation method you prefer.
    • Implemented basic license management, including license activations, deactivations, and both online and local license checks.

Handling Exceptions

Methods of License and LicenseManager classes throw exceptions if something went wrong. Put the methods that can produce exceptions in try...catch block.

LicenseSpringException is the base class of all SDK exceptions. The good practice is to implement separate logic for different types of exceptions. Below is the example of handling device id mismatch. Instead of closing the application, we can try to upgrade to a new device id algorithm. See: Hardware ID

C++
C#


Common Exceptions

Below is the list of the exceptions that can occur on any SDK request:

Exception

Definition

LicenseStateException

License is disabled, was reset or expired

SignatureMismatchException

In case signature returned by LicenseSpring server is not valid. E.g. if the response data was changed.

NoInternetException

NetworkTimeoutException

LicenseServerException

Connection-related errors: if there's no Internet or an internal server error occured. See Grace Period

ApiKeyException

If provided api key cannot be used for the request( is invalid, readonly or revoked).

AuthorizationException

Authorization failed, please check your proxy settings.

Handling C++ Errors

The LicenseHandler class of C++ SDK is exception-free by default. It provides an alternative way to implement licensing without exceptions but C-style error codes. Make sure to put error checks after LicenseHandler calls. 

To retrieve the error use the following methods:

C++


This class also contains several methods to check for error type, e.g. isLicenseStateError, isNoInternetError.

Example of handling LicenseHandler errors:

C++


Common Errors

Below is the list of the exceptions that can occur on any SDK request:

Error

Definition

eStdError

C++ standard exception encountered

eSignatureMismatchError

Server signature is not valid. E.g. if the response data was changed.

eNoInternetError

eNetworkTimeoutError

eServerError

Connection-related errors: if there's no Internet or an internal server error occured. See Grace Period

eInvalidApiKey

eReadOnlyApiKey

eRevokedApiKey

eApiKeyProductNotAllowed

If provided api key cannot be used for the request( is invalid, readonly or revoked).

eAuthorizationError

Authorization failed, please check your proxy settings.

Handling Swift errors

Swift SDK uses LSError compatible with NSError for error reporting.

Any SDK method marked as throwsproduces LSError in case of error. Possible error codes described as enum LSErrorCode.

Swift