Error Handling - Outputting Call Stack

ions

Access User
Local time
Today, 06:50
Joined
May 23, 2004
Messages
816
Can the Err ojbect give me the current Call Stack or do i have to code this myself if I want it to appear in my Error Log / Error Message?

Thank you
 
what do you mean by CALL STACK??

err will only give you methods and properties associated with the error that's in the object at the time you request it.
 
Maybe the Err object is misleading.

What I want is an Array that holds the Procedure Call Stack. Is there an object in VBA that holds that info? The Call Stack is available in the IDE but I want to access it in code.

Thanks
 
What I want is an Array that holds the Procedure Call Stack. Is there an object in VBA that holds that info?
i'm pretty sure there's not. but I have to ask, why are you looking at it? or why do you 'want' to look at it and track it?
 
A possible DIY example is to set up your error handler to allow errors to bubble upward and gather the information. Example:

Code:
Public Sub TryIt()
On Error GoTo Error_Handler

  A

Exit_Procedure:
  On Error Resume Next
  Exit Sub
Error_Handler:
  Select Case Err.Number
    Case vbObjectError
      MsgBox Err.Description, vbOKOnly + vbExclamation
    Case Else
      MsgBox Err.Number & ", " & Err.Description
  End Select
  Resume Exit_Procedure
  Resume
End Sub

Public Sub A()
On Error GoTo Error_Handler

  B

Exit_Procedure:
  On Error Resume Next
  Exit Sub
Error_Handler:
  Select Case Err.Number
    Case vbObjectError
      Err.Raise vbObjectError, "MyClass", "In Procedure A:" & vbNewLine & Err.Description, Err.HelpFile, Err.HelpContext
    Case Else
      MsgBox Err.Number & ", " & Err.Description
  End Select
  Resume Exit_Procedure
  Resume
End Sub

Public Sub B()
On Error GoTo Error_Handler

  C

Exit_Procedure:
  On Error Resume Next
  Exit Sub
Error_Handler:
  Select Case Err.Number
    Case vbObjectError
      Err.Raise vbObjectError, "MyClass", "In Procedure B:" & vbNewLine & Err.Description, Err.HelpFile, Err.HelpContext
    Case Else
      MsgBox Err.Number & ", " & Err.Description
  End Select
  Resume Exit_Procedure
  Resume
End Sub

Public Sub C()
On Error GoTo Error_Handler

  Debug.Print 1 / 0

Exit_Procedure:
  On Error Resume Next
  Exit Sub
Error_Handler:
  Select Case Err.Number
    Case Else
      Err.Raise vbObjectError, "MyClass", "In Procedure C:" & vbNewLine & Err.Number & ": " & Err.Description, Err.HelpFile, Err.HelpContext
  End Select
  Resume Exit_Procedure
  Resume
End Sub

The resulting error message would be:

Code:
In Procedure A:
In Procedure B:
In Procedure C:
11: Division by zero

You'd use MZ-Tools to automate the building of error handler.

Not as full-featured as this vbWatchDog, but YMMV.
 

Users who are viewing this thread

Back
Top Bottom