Attribute VB_Name = "ErrorHandling"
Option Explicit
'
' FILE AUTOMATICALLY GENERATED BY ESRI ERROR HANDLER ADDIN
' DO NOT EDIT OR REMOVE THIS FILE FROM THE PROJECT
'
'

Private Sub DisplayVersion2Dialog(sProcedureName As String, sErrDescription As String)
  Dim pForm As prjVBErrorAddIn.ErrorLog

  Set pForm = New prjVBErrorAddIn.ErrorLog

  pForm.SetErrorText "Record Call Stack Sequence - Bottom line is error line." & vbCrLf & vbCrLf & vbTab & sProcedureName & vbCrLf & sErrDescription
  pForm.Show

  Set pForm = Nothing
End Sub

Public Sub HandleError(ByVal bTopProcedure As Boolean, _
                       ByVal sProcedureName As String, _
                       ByVal lErrNumber As Long, _
                       ByVal sErrSource As String, _
                       ByVal sErrDescription As String, _
                       Optional ByVal version As Long = 1)
    ' Generic Error handling Function - This function should be called with
    ' the following Arguments
    '
    ' Boolean  -in-  True if called from a top level procedure - Event / Method / Property
    ' String   -in-  Name of function called from
    ' Long     -in-  Error Number (retrieved from Err object)
    ' String   -in-  Error Source (retrieved from Err object)
    ' String   -in-  Error Description (retrieved from Err object)
    ' Long     -in-  Version of Function (optional Default 1)
    
    
    ' Clear the error object
    Err.Clear

    ' Static variable used to control the call stack formatting
    Static entered As Boolean

    If (bTopProcedure) Then
        ' Top most procedure in call stack so report error to user
        ' Via a dialog
        If (Not entered) Then sErrDescription = vbCrLf & "Description" & vbCrLf & vbTab & sErrDescription
        entered = False
        If (version = 2) Then
          DisplayVersion2Dialog sProcedureName, sErrDescription
        Else
          Beep
          MsgBox "An error has occured in the application.   Record the call stack sequence" & vbCrLf & "and the description of the error." & vbCrLf & vbCrLf & _
                 "Error Call Stack Sequence " & vbCrLf & vbTab & sProcedureName & vbCrLf & sErrDescription, vbExclamation + vbOKOnly, "Unexpected Program Error"
        End If
    Else
        ' An error has occured but we are not at the top of the call stack
        ' so append the callstack and raise another error
        If (Not entered) Then sErrDescription = vbCrLf & "Description" & vbCrLf & vbTab & sErrDescription
        entered = True
        Err.Raise lErrNumber, sErrSource, vbTab & sProcedureName & vbCrLf & sErrDescription
    End If
End Sub

Public Function GetErrorLineNumberString(ByVal lLineNumber As Long) As String
  ' Test the line number if it is non zero create a string
  If (lLineNumber <> 0) Then GetErrorLineNumberString = "Line : " & lLineNumber
End Function

