Click to See Complete Forum and Search --> : Global Error Checking
Mark D. Scudder
May 1st, 2001, 02:41 PM
I know that you can define an error handler in a sub or function...but I've got a program that runs 24/7 for other people, even when I'm not around to see what it's (or they're) doing. Is there a way to have a global error handler for every line of code, just so i can grab the error message and write it to a log file before the program dies? That way I can catch the bugs and fix them, despite the end-user's always-helpful cries of "your program's a piece of crap." :-)
-Mark
-----
Mark D. Scudder
(www.markscudder.com)
Iouri
May 1st, 2001, 02:48 PM
You can use Erl function
When a run-time error occurs in a Visual Basic for Applications user- defined function with error handling
in effect, the Erl() function returns 0 unless a line number is specified in the user-defined function.
You can return a line number in the Erl() function by specifying a line number on or above the line that
causes the error. The Erl() function will return the line number currently in effect. You must specify
a numeric line number, not an alphanumeric line label. The Erl function() will only return a line number.
Dim x As Integer ' Declare variable.
On Error GoTo ErrorTest_Error
1 x = 1
2 x = 2
3 x = 5 / 0 ' Divide by zero error.
Exit Sub
ErrorTest_Error:
MsgBox "Error occurred in line #" & Erl
Resume Next
This proc will return -> Error occurred in line # 3
Line # >65529 is not supported
Iouri Boutchkine
iouri@hotsheet.com
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.