Error Handling
Error handling is an integral part of software development. This article provides effective ways to handle LicenseSpring errors and keep your application secure.
Prerequisites
Completed the Getting Started tutorial
Follow the Getting Started Tutorial, specifically:
Initialized
LicenseManager(orLicenseHandler) with your configuration using the appropriate settings.Created a
LicenseIDusing eitherLicenseID::fromKeyorLicenseID::fromUserfunction, 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 generation
try
{
license->localCheck();
}
catch(const DeviceNotLicensedException& ex)
{
// Handling specific error: trying to upgrade to new device id algorithm
license = m_licenseManager->relinkLicense(WinCryptographyId);
return;
}
catch(const LicenseSpringException& ex)
{
std::cout << "LicenseSpring exception encountered: " << ex.what();
}try
{
license.LocalCheck();
}
catch( DeviceNotLicensedException ex )
{
// Handling specific error: trying to upgrade to new device id algorithm
license = manager.RelinkLicense( DeviceIDAlgorithm.Gen3 );
return;
}
catch (LicenseSpringException ex )
{
Console.WriteLine( "LicenseSpring exception encountered: {0}", ex.Message );
}Common Exceptions
Below is the list of the exceptions that can occur on any SDK request:
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 License Checks (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:
This class also contains several methods to check for error type, e.g. isLicenseStateError, isNoInternetError.
Example of handling LicenseHandler errors:
Common Errors
Below is the list of the exceptions that can occur on any SDK request:
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 License Checks (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 throws produces LSError in case of error. Possible error codes described as enum LSErrorCode.
Last updated
Was this helpful?