Re: WHENEVER ANY ERROR
Posted in 1997
Jason Harris (jharris@westpac.com.au) wrote: }My 0.02 worths. } }I always thought that WHENEVER ERROR is a "COMPILER DIRECTIVE" and }has no effect at run time. Code sequentially in the file after the }WHENEVER ERROR statement will follow whatever is set. All the way }through the program until the next WHENEVER ERROR is hit. } }It is evaluated at COMPILE time not RUN time. It is a compiler directive. It affects the code generated at compile time, which in turn affects the behaviour of the code at run time, of course. One of the problems with WHENEVER as a compiler directive is that you cannot place it just anywhere in the source code; it is only allowed where an executable statement is allowed -- despite it being a compiler directive. What I was saying about WHENEVER ERROR GOTO is precisely the behaviour you talk about -- that the code sequentially in the (source) file after the WHENEVER ERROR statement will use whatever error handling is set all the way through the program until the next WHENEVER ERROR is hit. That means that if you say WHENEVER ERROR GOTO Label1 in FunctionA and don't turn it off again before the END FUNCTION for FunctionA, then the FunctionB which follows FunctionA in the source file needs a LABEL Label1 in it too, and the same for every following function. In my view, this is seldom the desired behaviour; however, it is the implemented behaviour and it always has behaved like that. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h> PS: Warning I do not reply to messages with anti-spam in the return path. }johnl@informix.com (Jonathan Leffler) wrote: }>Peter Lancashire <Peter.Lancashire.PL1@bayer.co.uk> wrote: }>>Alan Denney wrote: }>>>Jojean <jojean@aol.com> wrote: }>>>>We are changing some 4GL programs to use WHENEVER ERROR to }>>>>WHENEVER ANY ERROR. }>>>Good move, generally. }>> }>>I have found a nasty bug in 4GL 6.02 on SCO where attempts to turn off }>>the error trapping fail. This results in a C error in the next function }>>when it can't find the label the WHENEVER ERROR GOTO directive referred }>>to in the previous function. }> }>This is a (mis)feature of the WHENEVER statement, rather than a bug per }>se. If you use WHENEVER ANY ERROR GOTO in FunctionA(), then you should }>remember to turn it off (with WHENEVER ANY ERROR STOP) before the END }>FUNCTION for FunctionA(). If you don't, then the code which pops the }>arguments to FunctionB() which follows will use the same error handling }>as FunctionA(), so you have to have the same label in FunctionB() as you }>had in FunctionA(). [...] }> }>Remedies: }>1. Don't use WHENEVER ... GOTO }>2. Limit the scope of WHENEVER...GOTO to a single function. }>[...]