I have some code with various "On Error Goto" error handlers in a few places to handle some broken third party hardware. I was getting an overflow error (read from the Err variable) in a routine that doesn't have an error trap but is called by a routine that does. I always thought error traps were only valid in the routine they were declared, but it looks like an error in a subroutine can cause it to go to the calling function's error trap.
So I turned off the calling function's error trap and found my overflow and all is well. But before I did that, I spent some time trying to find a programatic way to get VB to return to its default error handling inside that routine (so I wouldn't have to modify outside code to debug), but I couldn't. The only error commands I could find:
On Error GoTo [label] On Error Resume Next On Error Goto 0 On Error GoTo -1
all turn on the manual error handling - is there a way to turn it off (back to the VB6 default)?
Here is what I do:
First turn on error handling like this if necessary in your Sub Main() or Sub Form_Load() Sub:
Now errors will be turned on.
Next, Use the On Error Resume Next and On Error GoTo {label} commands in combination with the Err object. Here is an example of emulating a try/catch/finally:
/Tools/Options/General/Error Handling