Open topic with navigation

TIBCO BusinessEvents® Enterprise Edition 6.3.1

# Examples

Exception handling syntax for the rule language grammar is presented through some examples.

## try/finally Example

    String localStatus = "default status";
    try {
        //readStatus might throw an exception
        localStatus = readStatus();
    } finally {
        //If readStatus() throws an exception,     //MyScorecard.status will be set to "default status"
        //but the exception won't be caught here.
        //Otherwise MyScorecard.status will be set to the
        //return value of readStatus()
        MyScorecard.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,     //MyScorecard.status will be set to "default status"     //Otherwise MyScorecard.status will be set to the     //return value of readStatus()
        MyScorecard.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,     //MyScorecard.status will be set to "default status"     //Otherwise MyScorecard.status will be set to the     //return value of readStatus()
    MyScorecard.status = localStatus;

## try/catch Example with Checking errorType and rethrow

    String localStatus = "default status";
    try {
        //readStatus might throw an exception
        localStatus = readStatus();
    catch(Exception exp) {
        if (exp@errorType == "java.lang.NullPointerException")
             throw exp;
        System.debugOut("readStatus() threw an exception with message " + exp@message);
    }
    //If readStatus throws an exception other than NullPpointerException,
    //MyScorecard.status will be set to "default status"
    //If readStatus throws NPE, MyScorecard.status will be set to "default status" and NPE will be re-thrown.
    //Otherwise MyScorecard.status will be set to the return value of readStatus()
    MyScorecard.status = localStatus;

Did you find this helpful?

YesNo
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO BusinessEvents® Enterprise Edition

Copyright © 2004-2024. Cloud Software Group, Inc. All Rights Reserved.