Exception handling can be added to any action components. Exception handling determines how errors from statements or functions are treated. The syntax is as follows:

         <action> ? [LOG][,][FAIL|STOP|NEXT|IGNORE]

The question mark handles errors generated by the function. The keywords, that control how an exception is handled are described in Exception handling keywords.

Table 1. Exception handling keywords

Keyword

Description

LOG

The exception is reported to the English log file and the non-English log file, if specified. When a remote exception chain is logged by ASL, the locale defined in the SM_LOCALE environment variable will be used. The VMware Smart Assurance System Administration Guide provides further information concerning the log files.

FAIL

The current rule exits with a failure status. If the failed expression is associated with the START rule, the DEFAULT rule is executed.

STOP

This is equivalent to calling the stop() function.

NEXT

The processing of actions in the current expression block stops. The rule, however, is not treated as failed rule.

IGNORE

The current action is ignored and processing continues as if nothing happened.

You can specify the LOG keyword with any of the other keywords.

To define the severity of the exception, arguments can be passed to LOG. Logging levels are set by using the syntax:

LOG("<logging_level>")

Valid logging keywords are (in increasing level of severity):

  • Debug

  • Notice or Informational

  • Warning (Default log value)

  • Error

  • Fatal or Critical

    When the exception is not specified, the default behavior for exceptions is LOG, NEXT. In other words, when an exception occurs, the error is logged and no other actions are performed in the current action block.

    Note:

    Do not confuse the question mark (?) used for exception handling with the question mark (?) used with patterns. “Maybe operator” on page 50 provides additional information.

    The following script demonstrates two different keywords to use for exception handling. The first exception occurs for:

    print(x) ? IGNORE;
    

    There is no value assigned to the variable x, so the function causes an exception. Since the keyword is IGNORE, the current line is skipped and the next line is executed.

    The second exception occurs for:

    print(y) ? FAIL;
    

    There is no value assigned to the variable y, so the function causes an exception. Since the keyword is FAIL, the current action block is not completed (and the following print statement is not executed) and the START rule fails. Whenever the START rule fails, the DEFAULT rule is executed.

    ASL Script (exception_do.asl)
    START
    do {
     print("Hello");
     print(x) ? IGNORE;
     print("OK");
     print(y) ? FAIL;
     print(“Here I am”);
    }
    DEFAULT 
    do {
     print("Default rule");
     stop();
    }
    Input:
    none
    Output:
    $ sm_adapter exception_do.asl
    Hello
    OK
    Default rule
    $