Consulting

Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 21 to 40 of 53

Thread: Global Error Handler

  1. #21
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    Quote Originally Posted by ''Howard Kaikow"
    I'd have to go check the bookmark in the most recent book I've been reading (a C# book) to find out what page I'm on.


    You know, now that I go back and read what you wrote, I see I misunderstood. When you said "Create a log file when the program starts and have ALL error handlers write info to that file" I incorrectly understood "record ALL errors in the log", which prompted those first two questions. Sorry 'bout that.

  2. #22
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by xCav8r
    I'm working on the last article myself. Prolly gonna combine that with the first then develop some options for logging and messaging. Initially I'll log to a file, but I'll enhance it as I have time with the ability to log to Access, SQL Server 2000, MySQL, and SQLite.
    Hi,

    Sound great to me I had no time yet.
    Be sure to put the finished error logging code over here. I'd love to try it out!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  3. #23
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    I'm rather fond of the method of recreating the stack that the second article suggests. I've done that now for several projects I'm working on. Not a little amount of work either. I thought I'd share something I've added to it. By just pushing the procedure name onto the stack, you don't get the module name or project. Not a big deal for something that's small, but if you're spanning several projects, that could get confusing.

    So, I've created constantsto capture the project name and module name, then a little function to concatenate them with the procedure name to push to the stack recreator. My default procedure now looks something like this...

    [VBA] Sub RoutineName()
    'Comments: What this routine does and how to use it

    If gcfHandleErrors Then On Error GoTo RoutineName_Error
    PushCallStack ConcatenateProjectNameAndModuleNameAndProcedureName( _
    gcstrProjectName, _
    mcstrModuleName, _
    "RoutineName")

    ' << Your code here >>

    RoutineName_Exit:
    PopCallStack
    Exit Sub

    RoutineName_Error:
    Select Case Err.Number
    'Local Error Handling
    Case Else
    GlobalErrHandler
    End Select
    Resume RoutineName_Exit
    End Sub
    [/VBA]

    And here's the function I'm currently using...

    [VBA] Function ConcatenateProjectNameAndModuleNameAndProcedureName( _
    ProjectName As String, _
    ModuleName As String, _
    ProcedureName As String)

    ' This function should be called by every procedure with error handling to
    ' concatenate ProjectName.ModuleName.ProcedureName to use for the log
    ' called by the global error handler. A public constant should be declared
    ' to house the project name, and a module level constant should be used
    ' to house individual module names to reduce the amount of customization
    ' required per procedure.

    If gcfHandleErrors Then On Error GoTo _
    ConcatenateProjectNameAndModuleNameAndProcedureName_Error
    PushCallStack gcstrProjectName _
    & mcstrModuleName _
    & ".ConcatenateProjectNameAndModuleNameAndProcedureName"
    ConcatenateProjectNameAndModuleNameAndProcedureName = ProjectName _ & "." & ModuleName _
    & "." & ProcedureName

    ConcatenateProjectNameAndModuleNameAndProcedureName_Exit:
    PopCallStack
    Exit Function

    ConcatenateProjectNameAndModuleNameAndProcedureName_Error:
    Select Case Err.Number
    Case Else
    GlobalErrHandler
    Resume ConcatenateProjectNameAndModuleNameAndProcedureName_Exit
    End Select
    End Function [/VBA]

    Log sample...

    Error Number: 11
    Error Description: Division by zero
    CallStack (0): TestLogError
    Date/Time: 6/17/2005 7:32:40 PM
    User: Marco
     
    Error Number: -2147467259
    Error Description: [Microsoft][ODBC Excel Driver] '(unknown)' is not a valid 
    path. Make sure that the path name is spelled correctly and that you are 
    connected to the server on which the file resides.
    CallStack (0): RealEstateStartup.modDataMerge.MergeTemplateWithData
    CallStack (1): RealEstateStartup.modLoadConfiguration.LoadFileExtenions
    CallStack (2): CodeLibrary.modAdoOperations.ReadDataFromWorkbook
    Date/Time: 6/17/2005 8:03:48 PM
    User: Marco
     
    Error Number: 76
    Error Description: Path not found
    CallStack (0): RealEstateStartup.modDataMerge.MergeTemplateWithData
    CallStack (1): CodeLibrary.modFTP.GetFile
    Date/Time: 6/17/2005 8:41:18 PM
    User: Marco
    I'm planning to add a few new things to the log:
    • Message sent to user
    • My own error description (in this case intended to be used to troubleshoot problems by employees of my client after my work for them is done)
    • Line number that generated error (don't have them in the code right now)

  4. #24
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    Looks good to me. Will have a play with it later.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  5. #25
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    I need a good line number generator now. The one I have inserts blank lines and numbers those. No good for Erl. Suggestions?

  6. #26
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by xCav8r
    I need a good line number generator now. The one I have inserts blank lines and numbers those. No good for Erl. Suggestions?
    Hi,

    Don't understand your question..what do you mean?

    The one you have? which one is that?
    More detail please...
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  7. #27

  8. #28
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    And that should mean what to me?
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  9. #29
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    Sorry, I thought you were asking what I was using to put line numbers into VBA. The add-in at that link is what I'm currently using, but it inserts blank lines and numbers those, and so I can't log the line where the error originated with Erl.

    [VBA] Sub StartBDAddIn()
    30
    On Error GoTo errorhandler
    40
    Dim oneAddin As COMAddIn
    50
    For Each oneAddin In Application.COMAddIns
    60
    If StrComp(oneAddin.ProgID, "bOffDevLib.bOffDevWord", vbTextCompare) = 0 Then
    70
    oneAddin.Connect = True
    80
    End If
    90
    Next
    100
    Exit Sub
    110
    errorhandler:
    120
    MsgBox "Error loading bOffDev COM Add-in: " & Err.Description
    130
    Err.Clear
    140
    Exit Sub
    End Sub
    [/VBA]

  10. #30
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    Ah Ok got it now.
    I'll read back in to things and come back to this one.

    I've never uses Err lines myself but I know you have to have linenummers in ALL of your code. Do you have that?

    Later..
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  11. #31
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    Well I'm not gonna use that addin myself thus not installing it!

    I did a little test if Err lines are easy to retrieve and they are.
    The test I did:[VBA]
    Option Explicit

    Sub GenerateError()
    Dim iNum As Integer
    Dim iDenom As Integer
    Dim iResult As Integer

    On Error GoTo Err_GenerateError
    1: iNum = 5
    2: iDenom = 0
    3: iResult = iNum / iDenom

    End_GenerateError:
    Exit Sub

    Err_GenerateError:
    MsgBox Err.Description & _
    " (" & Err.Number & ") occured on line " & Erl()

    Resume End_GenerateError
    End Sub
    [/VBA]

    So it seams quite easy to retrieve it and thus usefull. I think I'm gonna use it myself from now!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  12. #32
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    I only installed the addin for the line numbering, but because it adds blank lines as it numbers, it's not what I'm looking for. If you find something that numbers the code as you did in your example, I would be interested. I have found a number of things that add line numbers that cost $$$, but if I can find one for free, I'd rather use that.

  13. #33
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by xCav8r
    I only installed the addin for the line numbering, but because it adds blank lines as it numbers, it's not what I'm looking for. If you find something that numbers the code as you did in your example, I would be interested. I have found a number of things that add line numbers that cost $$$, but if I can find one for free, I'd rather use that.
    Ah..You're looking for a free tool!

    Well I like those as well!

    I use this VBE addin: http://www.mztools.com/v3/mztools3.htm
    And it does produce or remove line numbers or removes them...but if it does it the way you want it to???

    Enjoy!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  14. #34
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    You da man, Mousse!!!!!!!!!! Working like a charm. Nice add-in.

  15. #35
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by xCav8r
    You da man, Mousse!!!!!!!!!! Working like a charm. Nice add-in.
    Yepz..me like it a lot as well! You're Welcome!

    Mousse!!! right back at yah!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  16. #36
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    I love the ability to control the auto error handling.

  17. #37
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by xCav8r
    I love the ability to control the auto error handling.
    Me too...I'm sure it has much more tools you'd love!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  18. #38
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    I'm going nuts. How have I lived without this?????????????????

  19. #39
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by xCav8r
    I'm going nuts. How have I lived without this?????????????????
    Well You've actually learned more becuase you had to do everything manualy!!

    Now you have this great free tool you can automate a lot of things and so your fingers will finaly get that well deserved rest!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  20. #40
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    Got it working now with Access and SQL Server 2000. Before I do any more, since I'm going to submit this for a KB entry, I thought I'd solicit suggestions for other information to capture. Here's what I'm currently tracking:
    • Error Number
    • Error Description (from scripting engine)
    • Call Stack (ProjectName.ModuleName.ProcedureName)
    • Line Number originating error
    • Date/Time Stamp
    • Windows Account Name
    • Message that the user saw
    • Optional message from the developer to troubleshooter
    Preview of connection to Access with DAO...
    [VBA]
    Case gcintLogToAccess
    strPathToDatabase = "C:\Temp\vba_error_log.mdb"
    Set dbErrorLog = OpenDatabase(strPathToDatabase)
    End Select

    strSQL = "SELECT cs.lngIncidentID, " _
    & "cs.intCallStackPosition, " _
    & "cs.strCallStackProcedure " _
    & "FROM tblErrorCallStacks AS cs;"
    Set rstErrorCallStacks = dbErrorLog.OpenRecordset(strSQL)

    strSQL = "SELECT ei.lngIncidentID, ei.lngErrorNumber, " _
    & "ei.strErrorDescription, ei.datTimeStamp, " _
    & "ei.strDevComment, ei.strUserMessage, " _
    & "ei.intLineNumber, ei.strWindowsUser " _
    & "FROM tblErrorIncidents AS ei;"
    Set rstErrorIncidents = dbErrorLog.OpenRecordset(strSQL)

    With rstErrorIncidents
    .AddNew
    .Fields!lngErrorNumber = lngErrorNumber
    .Fields!strErrorDescription = strErrorDescription
    .Fields!datTimeStamp = Now
    .Fields!strDevComment = strDevComment
    .Fields!strUserMessage = UserMessage 'parameter of procedure
    .Fields!intLineNumber = intLineNumber
    .Fields!strWindowsUser = GetUserName 'function in another module
    .Update
    .MoveLast
    lngIncidentID = .Fields!lngIncidentID
    .Close
    End With

    intCounter = 1
    With rstErrorCallStacks
    For Each varCallStack In mastrCallStack
    If varCallStack <> "" Then
    .AddNew
    .Fields!lngIncidentID = lngIncidentID
    .Fields!intCallStackPosition = intCallStackPosition
    .Fields!strCallStackProcedure = varCallStack
    .Update
    End If
    intCounter = intCounter + 1
    Next varCallStack
    End With[/VBA]

Posting Permissions

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