Lee W, MVP
asked on
Determine Error Handling State
Is there any way to determine what the current error handling is in vb6?
Default error handling crashes the program displaying the error message.
If you use:
If you use:
And to disable graceful error handling, you use
But is there any way to tell if graceful error handling is on? Any way to tell that the last time an ON ERROR statement executed it was set to go to a label, resume next, or goto 0?
Default error handling crashes the program displaying the error message.
If you use:
ON ERROR GOTO Label
The program goes to the point in the code with the label and continues executing (presumably, you have defined what to do here to mitigate the error)If you use:
ON ERROR RESUME NEXT
The program will continue ignoring errors until it either can't run at all, you handle the errors, or you disable the resume next option. I often (but not always) use ON ERROR RESUME NEXT to allow the program to continue and then I explicitly check for an error number and handle the error there. For example:ON ERROR RESUME NEXT
X = 5
IF X = "bob" THEN X = "Bob"
IF ERR.NUMBER <> 0 THEN
'Handle the error
END IF
And to disable graceful error handling, you use
ON ERROR GOTO 0
But is there any way to tell if graceful error handling is on? Any way to tell that the last time an ON ERROR statement executed it was set to go to a label, resume next, or goto 0?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, that's what I was afraid of.
Reason being, I've taken over the coding of a (relatively) large application for a client and the previous coder(s) enabled and disabled error checking at times. And then I've done likewise (this is, by far, the largest VB6 project I've ever worked on). So I might have a sub routine or a function somewhere that I want to hard error out but I don't know if error checking is enabled somewhere in the earlier part of the call stack. I could set a variable every time I use "ON ERROR RESUME NEXT" and then when I turn it off, I can change the variable and test for it later, I was just hoping I could do something like this:
I suppose I could write my own error checking enabling/disabling function but that would then require going through all the code to change it. Not impossible, but a little tedious.
Reason being, I've taken over the coding of a (relatively) large application for a client and the previous coder(s) enabled and disabled error checking at times. And then I've done likewise (this is, by far, the largest VB6 project I've ever worked on). So I might have a sub routine or a function somewhere that I want to hard error out but I don't know if error checking is enabled somewhere in the earlier part of the call stack. I could set a variable every time I use "ON ERROR RESUME NEXT" and then when I turn it off, I can change the variable and test for it later, I was just hoping I could do something like this:
Sub Main
On Error Resume Next
Call Login
Call GetRegSettings
Call DisplayForm
ON Error Goto 0
End Sub
Sub Login
'Do stuff
If Err.ErrorCheckingState = vbErrResume Then 'For reference, Err.ErrorCheckingState is not real... sorry anyone reading this looking for a similar answer!
EnableErrorChecking = True
End If
On Error Goto 0 'Disable error trapping for this part
'Do More stuff
If EnableErrorChecking = True Then
On Error Resume Next 'Error trapping was on - re-enable it.
Else
'Do nothing - error checking wasn't on to begin with!
End If
End Sub
I suppose I could write my own error checking enabling/disabling function but that would then require going through all the code to change it. Not impossible, but a little tedious.
Was it your intention to award the points to Ryan? If so no problem; you win some you lose some, but I just wanted to check.
ASKER
Yes, that was my intention. But I did try to indicate appreciation for your comment too!
Open in new window