Handling Errors

DCL provides several mechanisms for detecting and handling errors that may occur during the execution of a command procedure. This section describes the $STATUS and $SEVERITY symbols and the SET ON and ON commands.

In addition, certain DCL commands including OPEN, READ, and WRITE can branch to a label upon certain conditions (see the section "Other DCL Commands That Branch," above).

The ON Command

This command directs DCL to take action depending on the severity of an error or interruption encountered during the execution of a command procedure. It takes effect at the point in the procedure at which it is encountered and is overridden by any subsequent ON commands as they are encountered.

The general format is

     $ ON condition THEN $ action 

You may specify actions depending on whether a WARNING, ERROR, or SEVERE_ERROR occurs, or when the user types CTRL/Y (interrupt).

Following the occurrence of an error with equal or greater severity than the level specified, the requested action will be carried out.

Some examples are as follows:

     $ on warning then $ continue     $ on warning then $ goto ERROR_HANDLER     $ on error then $ exit     $ on control_y then $ goto CTRLY_HANDLER 

The SET ON Command

During the execution of a command procedure, you may sometimes wish to ignore certain kinds of errors. For example, one line of a command procedure might delete a temporary file generated by a previous run. Suppose no such file exists?

The absence of that file may be perfectly normal, but DCL will not automatically know that. DCL would normally consider it an error and terminate the execution of your command procedure. Thus, DCL needs some method to suspend detection of errors for a short time.

The SET ON command enables error detection; SET NOON (set no on) disables it. The portion of our command procedure devoted to deleting temporary files would look like this:

     $ !     $ ! Delete temporary files from yesterday's run.     $ !     $ set noon               ! Temporarily disable detection of errors.     $ delete/log []*.TMP;*   ! Delete the files, if any.     $ set on                 ! Re-enable error detection.     $ ! 

$STATUS and $SEVERITY

For even finer-grained control over DCL error handling, DCL maintains the built-in symbols $SEVERITY and $STATUS. After each DCL command, these symbols contain information about the success or failure of the command that just finished.

$SEVERITY will hold one of the following values:

1—The command finished with NORMAL status (was successful).

3—The command finished with INFORMATIONAL status (was successful).

0—The command finished with WARNING status.

2—The command finished with ERROR status.

4—The command finished with SEVERE_ERROR status.

$STATUS will contain the exact status value from the command. Odd values indicate success, and even values indicate failure. The information contained in $SEVERITY is duplicated in the low three bits of $STATUS. You may check $STATUS against specific return values or simply for a severity level.

For example, place one of these lines directly after the DCL command you wish to check. "Action" can be almost anything, including GOTO or EXIT. This list does not contain all possible combinations:

     $ IF .NOT. $SEVERITY THEN $ action  ! WARNING or worse     $ IF $SEVERITY .EQ. 4 THEN $ action ! $severity = 4: SEVERE_ERROR.     $ IF .NOT. ($STATUS .AND. 1) THEN $ action  ! Any WARNING or worse     $ IF $STATUS .EQ. exact_value THEN $ action ! Checks for specific status. 



Getting Started with OpenVMS(c) A Guide for New Users
Getting Started with OpenVMS: A Guide for New Users (HP Technologies)
ISBN: 1555582796
EAN: 2147483647
Year: 2005
Pages: 215

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net