Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.4 KiB

  1. VERSION 1.0 CLASS
  2. BEGIN
  3. MultiUse = -1 'True
  4. Persistable = 0 'NotPersistable
  5. DataBindingBehavior = 0 'vbNone
  6. DataSourceBehavior = 0 'vbNone
  7. MTSTransactionMode = 0 'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "CErrorInfo"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. Public Event ReturnErrorInfo(strErrList As String)
  16. Private Type ErrorInfoStackEntry
  17. strErrMsg As String
  18. strFunction As String
  19. End Type
  20. Private m_ErrorInfoStack() As ErrorInfoStackEntry
  21. Private m_Description As String
  22. Private m_HelpContext As String
  23. Private m_HelpFile As String
  24. Private m_LastDllError As Long
  25. Private m_Number As Long
  26. Private m_Source As String
  27. Private m_strStackDump As String
  28. Private Sub Class_Initialize()
  29. ReDim m_ErrorInfoStack(0)
  30. m_strStackDump = ""
  31. End Sub
  32. Public Function Dump(Optional bDumpErrorAndClear As Boolean = True) As String
  33. Dim iX As Long
  34. Dim strStackDump As String
  35. strStackDump = ""
  36. strStackDump = strStackDump & "*** VB ERROR Occurred ***" & vbCrLf & vbCrLf & _
  37. "Error: 0x" & Hex(m_Number) & " - " & vbCrLf & _
  38. vbTab & "Description: " & m_Description & vbCrLf & _
  39. vbTab & "Source: " & m_Source & vbCrLf & _
  40. vbTab & "HelpFile: " & m_HelpFile & vbCrLf & _
  41. vbTab & "HelpContext: " & m_HelpContext & vbCrLf & _
  42. vbTab & "LastDLLError: " & m_LastDllError & vbCrLf & _
  43. vbCrLf & "Occurred in Function: "
  44. For iX = 0 To UBound(m_ErrorInfoStack)
  45. If (iX > 0) Then
  46. strStackDump = strStackDump + vbTab + "which was called From: "
  47. End If
  48. With m_ErrorInfoStack(iX)
  49. strStackDump = strStackDump + .strFunction + " - " + _
  50. .strErrMsg & vbCrLf
  51. End With
  52. Next
  53. Dump = m_strStackDump & strStackDump
  54. If (bDumpErrorAndClear) Then
  55. MsgBox Dump, vbCritical, "Error"
  56. Err.Clear
  57. Class_Initialize
  58. End If
  59. End Function
  60. Public Sub SetInfo( _
  61. Optional ByVal strFunction As String = "<<Unspecified Function>>", _
  62. Optional ByVal strErrMsg As String = "" _
  63. )
  64. Dim iCaller As Long
  65. iCaller = UBound(m_ErrorInfoStack)
  66. With m_ErrorInfoStack(iCaller)
  67. .strFunction = strFunction
  68. .strErrMsg = strErrMsg
  69. End With
  70. If (iCaller = 0) Then
  71. m_Description = Err.Description
  72. m_HelpContext = Err.HelpContext
  73. m_HelpFile = Err.HelpFile
  74. m_LastDllError = Err.LastDllError
  75. m_Number = Err.Number
  76. m_Source = Err.Source
  77. m_strStackDump = ""
  78. RaiseEvent ReturnErrorInfo(m_strStackDump)
  79. End If
  80. ReDim Preserve m_ErrorInfoStack(iCaller + 1)
  81. End Sub
  82. Public Sub SetInfoAndDump( _
  83. Optional ByVal strFunction As String = "<<Unspecified Function>>", _
  84. Optional ByVal strErrMsg As String = "" _
  85. )
  86. SetInfo strFunction, strErrMsg
  87. Dump
  88. End Sub
  89. Public Sub SetInfoAndRaiseError( _
  90. Optional ByVal strFunction As String = "<<Unspecified Function>>", _
  91. Optional ByVal strErrMsg As String = "" _
  92. )
  93. SetInfo strFunction, strErrMsg
  94. Err.Raise Err.Number
  95. End Sub