CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1

    Global Error Checking

    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)

  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Global Error Checking

    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
    [email protected]
    Iouri Boutchkine
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured