Adding message to stack

I have been chasing a bug for a while without success.

When an unhandled exception happens, I receive the stack by email.

Problem is, I need more precise indications to really fix the bug.

Is there any way to add a message to the stack, a bit like log() does ?

1 Like

The closest thing I’ve done like this is to add a dictionary to the app class and write a method on App like this:

Sub AddToInnerStack(methodname as string, value as string)
Dim myStack() as string = mInnerStack.Lookup(methodName, Nil)
If myStack = nil then
  MyStack = Array(value)
  MyStack.AddRowAt 0, value
End If
MInnerStack.value(methodName) = myStack
End Sub

And then in UnhandledException, just extract the method name from the top stack item so you can pull it from the dictionary if it exists.

You would call it like this:

App.AddToInnerStack(currentMethodName, “call to server API”)

You will probably want a way to clear it when the method is done too. Be patient, I’m remembering off the top of my head.

You can do this by making a class that calls the above method (you could even make the dictionary and method above into shared entities of this class) and then have this class clear the local stack when it goes out of scope. That way you don’t have to remember to do it.

I can go dig up that class if you think it would be useful to you.

That is great. Thank you Greg. Frankly, I did not see where to start.

Yes, indeed, if you could find the class you created, that would be superb.

Just getting up for the day, so it’ll be a few minutes.

…assuming my machine ever finishes the 10.15.6 supplemental update… :face_with_symbols_over_mouth:

1 Like

I’ve extracted the class and made an example project. Keep in mind that the project hasn’t been updated for API 2 yet.


This will insert the log entries that you add into the stack just above the method where the exception occurred.

I mis-remembered the Destructor thing however. Class destructors fire even if exceptions occur, and unfortunately before UnhandledException does, so we can’t use that here.

Oh, and if you want to get entries for all methods in the entire stack, remove the

Exit For i

on line 32 of the ApplyTo method.
Gimme a sec, that’ll hang the app. :stuck_out_tongue:

1 Like

Ok, I updated the project. ApplyTo now takes a second parameter which lets you tell it whether you just want to add log entries for the first method it finds or for all of the methods it finds.