Question : Global Error Handler and On Error Resume Next

I have an error handler in the entry point routine of my app. I want all errors in downstream procedures to GoTo this error handler. Trouble is I have a lot of downstream procedures that use On Error Resume Next...On Error GoTo 0 which overrides the On Error GoTo Error_Handler in the entry point routine.

I've tried replacing On Error GoTo 0 with On Error GoTo Error_Handler but that produces a line label not found error. In downstream functions, is there a way to use On Error Resume Next and then reset the On Error behavior to On Error GoTo Error_Handler instead of On Error GoTo 0?

Answer : Global Error Handler and On Error Resume Next

I applaud you for wanting a common error handler.  Let me explain how I do it.

Create a global function for your common error handler logic.  The "the entry point of your app" may work--I don't know--it needs to be callable from anywhere. Let's call that functio ErrorRoutine().

Then code all suboutines something like this:


Private Sub MySub ()
On Error GoTo Finish
....<errors will be trapped>

On Error Resume Next
...<errors will not be trapped here>
On Error GoTo Finish

....<errors will be trapped>

Finish:
If err.number then if ErrorRoutine (vbRetry) = vbRetry then Resume  
...<subroutine housekeeping goes here>
Exit Sub



My version of ErrorRoutine evaluates for the retry parameter and if present issues an abort, cancel, retry prompt.  This permits the failing operation to be retried (which I find useful for debuggin).






Random Solutions  
 
programming4us programming4us