• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Text Templates
    • Templated Reporting System
    • HTML, Markdown, and JavaScript Integration
    • Action Invoker
      • Overview
      • Execution Environments
      • Security, Resource Management, and Formatting Options
      • Base Actions
        • execute Action
        • registerAccessToken Action
        • throwException Action
      • Application Namespace
      • Clipboard Namespace
      • Data Namespace
      • Dictionary Namespace
      • File Namespace
      • Hash Namespace
      • Localhost Namespace
      • Logic Namespace
      • Message Namespace
      • Path Namespace
      • Settings Namespace
      • Sqlite Namespace
      • System Namespace
      • UI Namespace
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataManager>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

throwException Action

Format
CS.throwException(message := ...
               
ʃ, name := ...ʅ
               
ʃ, cause := ...ʅ)
ArgumentDescriptionTypes / Required
messageThe error message.string
required
nameThe name of the error.
The default value is "ActionInvokerError".
string
not required
causeThe cause of the error.string, number, boolean, array, object
not required
Description
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.
Return Value
The action does not return.
Exceptions
The action throws a different exception from the one intended if any of its arguments are not specified in a valid form.
Example (JavaScript)
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
    });
}
See also: Action Invoker Overview, UI.close Action