Handling DCL ON ERROR actions after first error?

1.1k views Asked by At

The OpenVMS DCL command HELP ON EXAMPLE displays:

ON

Examples

   1.$ ON SEVERE_ERROR THEN CONTINUE

     A command procedure that contains this statement continues
     to execute normally when a warning or error occurs during
     execution. When a severe error occurs, the ON statement signals
     the procedure to execute the next statement anyway. Once
     the statement has been executed as a result of the severe
     error condition, the default action (ON ERROR THEN EXIT) is
     reinstated.

According to the help if neither [-]x.for nor [-]y.for exist then the last two lines will not be executed:

$ on error then $ continue
$ rename [-]x.for []
$ rename [-]y.for []
$ type *.for

Is there a way to set the ON ERROR handling as in the first line w/o placing an ON ERROR statement between each line of the script?

1

There are 1 answers

0
user2116290 On

If the ON ERROR fires, you have to re-establish it. It looks like you don't know whether any of the files exists. So the ON ERROR needs to be re-established after the first failing command.

You can do this in a subroutine, like in:

$ on error then $ gosub on_error
$ rename [-]x.for []
$ rename [-]y.for []
$ on error then $ exit
$ type *.for
$ exit
$
$ on_error:
$ on error then $ gosub on_error
$ return

Also, you can handle this differently, with disabling error checking (SET NOON):

$ set noon
$ rename [-]x.for []
$ rename [-]y.for []
$ set on
$ type *.for

or establishing error handling only for sever errors (ON SEVERE_ERROR):

$ on severe_error then $ exit
$ rename [-]x.for []
$ rename [-]y.for []
$ on error then $ exit
$ type *.for