Results 1 to 3 of 3

Thread: need help bad, error trapping

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    15
    I'm writing a error trapping and logging routine for
    a program I made a few weeks ago. It has some
    quite long functions, so I made a error logging
    routine. The program is called from the other functions
    like as below,

    sub test
    on error goto error

    end sub <-----------------------------------
    error: |
    call errorfunc |
    end sub |
    |
    I even tried it by changing the first end sub | to end,
    but my program stops executing every time somewhere.
    I need the program to continue through the errors. but log them so I can go back and fix them for different customers
    below is my error function if you're interested.



    Public Function LogError(ByVal ErrDateTime As Date, ByVal procname As String, ByRef ErrObj As ErrObject, Optional FormObject As Object, Optional CommandString As String)
    Dim intFileO As Integer
    ErrDateTime = (Date)

    On Error Resume Next

    intFileO = IntFile(0)
    MsgBox ("An error occured, and a Log file is being created")
    Open App.Path & "\Error.log" For Append As intFileO

    If IsMissing(FormObject) And IsMissing(CommandString) Then
    Write #intFileO, ErrDateTime, procname, ErrObj.Description,
    ErrObj.Source
    ElseIf Not IsMissing(FormObject) And Not IsMissing(CommandString) Then
    Write #intFileO, ErrDateTime, procname, ErrObj.Description,
    ErrObj.Source , FormObject.Caption, CommandString
    ' a routine to dump all values found in a form
    Call DumpFormValues(intFileO, frmRecordCard)
    ElseIf Not IsMissing(CommandString) Then
    Write #intFileO, ErrDateTime, procname, ErrObj.Description,
    ErrObj.Source , CommandString
    End If

    Close intFileO
    On Error GoTo 0
    Err.Clear
    On Error GoTo errhndlr
    End Function
    errhndlr: Call LogError(ErrDateTime, procname, ErrObj, FormObject, CommandString)
    End Function

  2. #2
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810
    Always use the 'exit function' or 'exit sub' before the error handler.

    This will fix yr prb.
    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

  3. #3
    Addicted Member
    Join Date
    Aug 2000
    Location
    Columbus Ohio
    Posts
    217

    End is bad

    Jerry is correct, by switching to end you exit the application. Using Exit sub and function would fix the problem
    Chris

    [email protected]
    Windows XP RC2 B2526
    Visual Studio.Net Beta 2
    C++, VB, VB.Net, ASP, PHP

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