on error goto nowhere

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Here's one for the gurus.

I tried to implement several error-handlers in one subprogram, each to
handle different errors at different stages in the execution. However, no
matter what I do, it seems that only the 1st error handler that is activated
will ever work. Even if it is subsequently deactivated, and a different
error-handler enabled, the new one is ignored when an error occurs.

I realised I have struck this problem in VB4 as well as VBA. My workaround
is to put each task that needs a specific error handler into a separate
subprogram, but this gets messy. Anyway, is it true that only one error
handler can ever be activated (even if subsequently deactivated) in a given
context? Or, have I fallen into some sort of 'error trap' myself?
 
You cannot have a stack of error handler all running at once in one
procedure.

When a procedure has an error handler running, and it calls another
procedure that has its own error hander, you have entered an error handling
stack, but it is still only one per procedure.

It is possible to put labels into different parts of your procedure where
you expect errors to occur, and test ERL to find out the most recently
encountered label. But this gets *really* messy, and slows execution. Better
to create separate functions with their own error handlers for hose lines
that are likely to error, rather than try to handle all the cases in one
monster procedure.
 
Allen_N said:
I tried to implement several error-handlers in one subprogram, each to
handle different errors at different stages in the execution. However, no
matter what I do, it seems that only the 1st error handler that is activated
will ever work. Even if it is subsequently deactivated, and a different
error-handler enabled, the new one is ignored when an error occurs.

I realised I have struck this problem in VB4 as well as VBA. My workaround
is to put each task that needs a specific error handler into a separate
subprogram, but this gets messy. Anyway, is it true that only one error
handler can ever be activated (even if subsequently deactivated) in a given
context? Or, have I fallen into some sort of 'error trap' myself?


I've never seen that effect. Errors have always gone to the
<errhandler> specified on the last **executed** On Error
GoTo <errhandler> statement.

OTOH, I have rarely needed to use more than one handler to
take care of all the errors in a procedure.
 
Back
Top