Chapter 1 Rule Language Grammar : Exception Handling

Exception Handling
The BusinessEvents rule Language includes an Exception type that has try/catch/finally commands to handle exceptions. The try/catch/finally commands behave like their same-name Java counterparts.
Advisory Events  You can also use the special AdvisoryEvent event type to be notified of exceptions that originate in user code but that are not caught with the catch command. To use the AdvisoryEvent, click the plus sign used to add a resource to the declaration. AdvisoryEvent is always available in the list of resources.
This section describes the try/catch/finally commands.
Syntax
These combinations are allowed:
try    try {
       try_statements
      }
catch  catch (Exception identifier) {
        catch_statements
      }
finally   finally {
         finally_statements
      }
When using the catch command, assignment of the Exception type is mandatory, and you are limited to one catch block.
Examples
This section provides some examples to demonstrate use of exception handling.
try/finally Example

 
String localStatus = "default status";
try {
//readStatus might throw an exception
localStatus = readStatus();
} finally {
//If readStatus throws an exception,
    //ScoreCard.status will be set to "default status"
//but the exception won't be caught here.
//Otherwise ScoreCard.status will be set to the
    //return value of readStatus()
Scorecard.status = localStatus;
}

 
try/catch/finally Example

 
String localStatus = "default status";
try {
    //readStatus might throw an exception
    localStatus = readStatus();
} catch(Exception exp) {
    System.debugOut("readStatus() threw an exception with message"
                     + exp@message);
} finally {
    //If readStatus throws an exception,
    //ScoreCard.status will be set to "default status"
    //Otherwise ScoreCard.status will be set to the
    //return value of readStatus()
    Scorecard.status = localStatus;
}

 
try/catch Example

 
String localStatus = "default status";
try {
    //readStatus might throw an exception
    localStatus = readStatus();
} catch(Exception exp) {
    System.debugOut("readStatus() threw an exception with message "
             + exp@message);
}
    //If readStatus throws an exception,
    //ScoreCard.status will be set to "default status"
    //Otherwise ScoreCard.status will be set to the
    //return value of readStatus()
Scorecard.status = localStatus;