skyfox
02-18-2008, 07:07 PM
Is this Ok or am I asking for Trouble.
Private Sub Do_something()
On error goto FAILURE
Code here........
Exit Sub
FAILURE:
On Error Resume Next
Code to Handle Original Error
End Sub
mkaras
02-18-2008, 10:14 PM
When you follow the sequence you have shown the "On Error Resume Next" statement would cause errors that arise from executing the "...Code to Handle Original Error" to be ignored.
PrOpHeT
02-19-2008, 08:25 AM
you can however use the err.clear method to reset the first error after it has been handled, this essentially resets the error to 0. From what I understand vb does this automatically at the end of each method so errors remain local in scope to the method where they are raised.
If you handler an error reset the err object and proceed, any new errors should re trip the on error statement.
NOTE: this process is much more elegant in .net
MikeJoel
02-19-2008, 09:10 AM
May I suggest if you need to trap errors in you error control, a simple way is
to say the error codes and such to variables then turn on error control and your code.
Mike
the master
02-19-2008, 09:19 AM
After handling an error you can add "resume next" to jump back up to where the error happened. If you want an error handler within an error handler then it is possible. I have used it sometimes when different code needs to be run if there is an error but that other code may cause its own error
on error goto erh1
'Do your code here
exit sub
erh1:
on error goto erh2
'Do your other code here if you get an error
exit sub
erh2:
'Something went really wrong if you get here!
Cerian Knight
02-19-2008, 11:31 AM
For additional information on error handling conventions, read through and follow the links within this thread:
http://www.xtremevbtalk.com/showthread.php?t=274290