website logo
⌘K
Getting Started
Introduction
Basic Concepts
Opening an Account
Creating & Configuring Products
Integrating SDK and Configuring License Fulfillment
Activate a Key-Based License
Vendor Platform
Issuing New Licenses
License Detail View
Order Detail View
Customer Detail View
Metadata
Analytics
Settings
Product Configuration
Product Features
Product Custom Fields
Product Versioning
License Policies
Product Bundles
License Entitlements
License Types
Activations & Device Transfers
Features
Custom Fields
License Start Date
License Note
Maintenance Period
Trial Licenses
Floating Licenses
License Activation Types
Portals
End-User Portal
Offline Portal
Air-Gapped Portal
License API
License API Authorization
License Activation/Deactivation
License Check
Consumption
Floating
Trial Key
Product Details
Device Variables
Changing Password
Management API
Making API Requests
Management API Authorization
Customer
Product
Order
License
Device
Analytics
SDKs
Tutorials
.NET/C# SDK
.NET/C# Management SDK
C++ SDK
Java SDK
Python SDK
Go SDK
Delphi SDK
Swift/Objective-C SDK
Android SDK
Unity SDK
Errors and Response Codes
Floating Server
API Reference
Deployment
Configuration
Floating Server UI
Securing the Server
Whitelabeling
FAQ
Floating Server Changelog
Integrations
Salesforce
FastSpring
Stripe
Shopify
Common Scenarios
Single Sign On (SSO)
Glossary
General
SDK Glossary
Vendor Platform
Product Configuration Glossary
License Configuration
Postman Collections
Frequently Asked Questions
Changelog
License API changelog
Platform changelog
Docs powered by
Archbee
SDKs
...
Tutorials
Best Practices

Error Handling

9min

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#
|
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:

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++
|
bool LicenseHandler::wasError() const; //check if there was an error
LSErrorCode LicenseHandler::getLastError() const; //get code of the last error
const std::string& LicenseHandler::getLastErrorMsg() const;//get message of the last error


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

Example of handling LicenseHandler errors:

C++
|
licenseHandler.checkLicenseLocal();
if( licenseHandler.wasError() )
{
    if( licenseHandler.getLastError() == eDeviceError )
        licenseHandler.relinkLicense( WinCryptographyId );
    else
        std::cout << "LicenseSpring error encountered: " << licenseHandler.getLastErrorMsg();
}


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
|
do {
    try license.fullCheck()
} catch let error as LSError {
    print("LicenseSpring error: \(error)")
} catch {
    print("Unknown error: \(error)")
}




Updated 05 Sep 2023
Did this page help you?
PREVIOUS
License Checks
NEXT
Custom Fields Usage
Docs powered by
Archbee
TABLE OF CONTENTS
Prerequisites
Handling Exceptions
Common Exceptions
Handling C++ Errors
Common Errors
Handling Swift errors
Docs powered by
Archbee