| Argument | Description | Types / Required |
| message | The error message. | string
required |
| name | The name of the error.
The default value is "ActionInvokerError". | string
not required |
| cause | The cause of the error. | string, number, boolean, array, object
not required |
The
throwException action throws an exception in the current execution environment. The arguments are based on properties present in JavaScript's
Error object. The
message is the text used to described the error, typically specified as an easily understood description of the error. The
name can be used to categorize classes of error messages. The
cause allows you to provide more context for the error.
All
execution environments other than CSPro Logic support exception handling. Exceptions that are thrown using this action are handled as if they were thrown using native exception handling. In the CSPro Logic execution environment, thrown exceptions are displayed as error messages.
If you want to throw an exception from one execution environment to another, the
UI.close action supports throwing an exception from a
HTML dialog or
web view that is introduced to the calling execution environment.
The action does not return.
The action throws a different exception from the one intended if any of its arguments are not specified in a valid form.
This example shows how the same exception can be thrown using the JavaScript Error object, or by using the Action Invoker.
function Divide(dividend, divisor) {
if( divisor != 0 ) {
return dividend / divisor;
}
// using JavaScript Error
const error = new Error(`You cannot divide ${dividend} by ${divisor}.`, { cause: [ dividend, divisor ] });
error.name = "DivideByZeroError";
throw error;
// using the Action Invoker
CS.throwException({
message: `You cannot divide ${dividend} by ${divisor}.`,
name: "DivideByZeroError",
cause: [ dividend, divisor ]
});
}
try {
Divide(808, 0);
}
catch(error) {
CS.UI.alert({
title: error.name,
text: error.message
});
}