How to get stack info programatically?

Hello,

I’m trying to debug some code in the field. I would like to add some code to a project so that whenever it pops out of a loop, I can have a record to show me what function it goes into and some properties I have built in.

Is there a way to do this? If so, how??

Thanks,
Tim

Check into the Runtime object.

You can use my ExceptionHandler for this. See Xojo + Alfred .

2 Likes

Hi Eric.

I don’t think that will do it. Something like CurrentMethodName that I can get from anywhere in the project.

@Beatrix_Willius - Thank you, I will look into your suggestion!

Tim

Hello Beatrix

The example for Alfred, did not come down as a project or anything that I can load into Xojo. I am using a Windows 11 machine, which may make a difference.

Tim

You can raise an exception whenever you want, just catch it and inspect the stack.

try
  raise new RuntimeException

catch ex as RuntimeException
  // ex.Stack

end try
3 Likes

It’s the first file to download:


The result is a nicely formatted information:

2024-09-27 08:29:40 An error happened:
2024-09-27 08:29:40 Class/Method: Window1.Method2
2024-09-27 08:29:40 Time: 27. Sep 2024 08:29:40 258275992
2024-09-27 08:29:40 Type of Error: NilObjectException
2024-09-27 08:29:40 Error Number: 0
2024-09-27 08:29:40 Error Message: 
2024-09-27 08:29:40 --------------------------
2024-09-27 08:29:40 Stack:
2024-09-27 08:29:40 
Sub Window1.Window1.Method2(Window1.Window1)
Sub Window1.Window1.Method1(Window1.Window1)
Sub Window1.Window1.Button1_Pressed(Window1.Window1, DesktopButton)
Sub Delegate.IM_Invoke(DesktopButton)
Sub AddHandler.Stub.20()
Sub DesktopApplication._CallFunctionWithExceptionHandling()
2024-09-27 08:29:40 Stack done
1 Like