AdapterException

Special Exception class that we encourage you to use in your Adapters to indicate that something has gone wrong that cannot be recovered from.

Using this custom exception allows us to surface the messages you write on the exception directly to users to help them understand what went wrong.

Definition

/**
 * Exception related to, and thrown by, Adapters.
 */
global class AdapterException extends Exception {}

Usage

You can throw the exception outright if you know things are in a bad state.

Example 1

if(thingsAreBroken) {
    throw new valence.AdapterException('Everything exploded!');
}

Example 2

Or you can wrap a low-level exception and add some context, giving us the best chance of surfacing an accurate error.

try {
    complexOperation();
}
catch(NullPointerException npe) {
    throw new valence.AdapterException('Complex Operation failed.', npe);
}