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.

139 lines
4.2 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 = "ExtendedErrorInfo"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Attribute VB_Description = "Provides Extended Error Information for Debugging Purposes."
  15. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  16. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  17. Option Explicit
  18. Public Event ReturnExtendedErrorInfo(strErrList As String)
  19. Private Type ErrorInfoStackEntry
  20. strErrMsg As String
  21. strFunction As String
  22. End Type
  23. Private m_ErrorInfoStack() As ErrorInfoStackEntry
  24. Private m_Description As String, _
  25. m_HelpContext As String, _
  26. m_HelpFile As String, _
  27. m_LastDllError As Long, _
  28. m_Number As Long, _
  29. m_Source As String
  30. Private m_strStackDump As String
  31. #If NEEDED_ONLY Then
  32. ' This is an internal Collection of Plug-In Error Handlers to be consulted in
  33. ' case of an Error.
  34. Private m_colExtendedErrorInfoPlugIns As Collection
  35. #End If
  36. Private Sub class_Initialize()
  37. ReDim m_ErrorInfoStack(0)
  38. m_strStackDump = ""
  39. #If NEEDED_ONLY Then
  40. Set m_colExtendedErrorInfoPlugIns = New Collection
  41. #End If
  42. End Sub
  43. Public Function Dump(Optional bDumpErrorAndClear As Boolean = True) As String
  44. Dim iX As Integer
  45. Dim strStackDump As String
  46. strStackDump = ""
  47. strStackDump = strStackDump & "*** VB ERROR Occurred ***" & vbCrLf & vbCrLf & _
  48. "Error: " & m_Number & " - " & vbCrLf & _
  49. vbTab & "Description: " & m_Description & vbCrLf & _
  50. vbTab & "Source: " & m_Source & vbCrLf & _
  51. vbTab & "HelpFile: " & m_HelpFile & vbCrLf & _
  52. vbTab & "HelpContext: " & m_HelpContext & vbCrLf & _
  53. vbTab & "LastDLLError: " & m_LastDllError & vbCrLf & _
  54. vbCrLf & "Occurred in Function: "
  55. For iX = 0 To UBound(m_ErrorInfoStack)
  56. If (iX > 0) Then
  57. strStackDump = strStackDump + vbTab + "which was called From: "
  58. End If
  59. With m_ErrorInfoStack(iX)
  60. strStackDump = strStackDump + .strFunction + " - " + _
  61. .strErrMsg & vbCrLf
  62. End With
  63. Next
  64. Dump = m_strStackDump & strStackDump
  65. If (bDumpErrorAndClear) Then
  66. MsgBox Dump, vbCritical, "Error"
  67. Err.Clear
  68. class_Initialize
  69. End If
  70. End Function
  71. Public Sub SetInfo(Optional ByVal strFunction As String = "<<Unspecified Function>>", _
  72. Optional ByVal strErrMsg As String = "")
  73. Dim iCaller As Integer
  74. iCaller = UBound(m_ErrorInfoStack)
  75. With m_ErrorInfoStack(iCaller)
  76. .strFunction = strFunction
  77. .strErrMsg = strErrMsg
  78. End With
  79. If (iCaller = 0) Then
  80. m_Description = Err.Description
  81. m_HelpContext = Err.HelpContext
  82. m_HelpFile = Err.HelpFile
  83. m_LastDllError = Err.LastDllError
  84. m_Number = Err.Number
  85. m_Source = Err.Source
  86. m_strStackDump = ""
  87. RaiseEvent ReturnExtendedErrorInfo(m_strStackDump)
  88. End If
  89. ReDim Preserve m_ErrorInfoStack(iCaller + 1)
  90. End Sub
  91. #If NEEDED_ONLY Then
  92. Function AddExtendedErrorInfoPlugIn(oXErrPlugIn As IExtendedErrorInfoPlugIn)
  93. m_colExtendedErrorInfoPlugIns.Add oXErrPlugIn
  94. End Function
  95. Function RemoveExtendedErrorInfoPlugIn(oXErrPlugIn As IExtendedErrorInfoPlugIn) As Boolean
  96. RemoveExtendedErrorInfoPlugIn = False
  97. Dim oXerrInColl As IExtendedErrorInfoPlugIn
  98. Dim iX As Integer, iMax As Integer
  99. iMax = m_colExtendedErrorInfoPlugIns.Count
  100. For iX = 0 To iMax
  101. If (m_colExtendedErrorInfoPlugIns.Item(iX) Is oXErrPlugIn) Then
  102. m_colExtendedErrorInfoPlugIns.Remove iX
  103. Exit For
  104. End If
  105. Next iX
  106. If (iX <= iMax) Then
  107. RemoveExtendedErrorInfoPlugIn = True
  108. End If
  109. End Function
  110. #End If