Proper way to getStackTrace()?


I’m looking for a way to collect debug info from testers for exceptions thrown.
And while handling ungaugherrorevents is working, I can’t get the stack trace.
In console (html, desktop etc) every line is printed fine but in the code I can’t access it.

Is there any way to access stack trace with line numbers etc. in the code? So I can make my own error handler (saving error logs to file, clipboard etc)

Thank you

I believe that our method of using UncaughtErrorEvent is correct, where the event type is not always of type Error, but could be any object that is thrown. Unfortunately, though, most errors will not be wrapped in an object.

One thing you could try is adding to private function __handleError (e:Dynamic):Void { in the “openfl/display/Stage.hx” class (line 1229 in the latest development sources), something like this:

if (e != null && (e, String)) {
    e = new Error (cast e);

Then more errors would be of type Error, and provide an error.getStackTrace () method, which is more convenient than alternatives.

There are other ways to get call stacks, but the cleanest might be for us to push it into an error object, so we can sanitize it or handle platform-specific differences

1 Like

Thank you, I’ll see what I can do without breaking future updates

Happy to make updates if we come up with a better behavior here :slight_smile:

1 Like