Fork us on GitHub

Better Error Logging

Use a new API to track hidden stack traces
Better Error Logging

Better Error Logging

A common pain point in most GUI frameworks is the hidden stack traces. When we have an app in production we get occasional emails from crash protection which are cryptic and hard to figure out. They usually start with the EDT loop and make no sense.

The reason for that is callSerially(). When we have code that invokes callSerially we essentially lose the previous stack trace. So your stack trace would look roughly like this:

        at com.mycompany.MyClass.myMethod(
        at com.codename1.ui.Display.edtLoopImpl(
        at com.codename1.ui.Display.mainEDTLoop(

For most cases you can just fix line 400 of MyClass so it won’t throw an exception but you might be hiding a worse bug. Lets say that line fails because it expects a specific condition to exist in the app and that condition isn’t met. A good example for this would be logged in users. Lets say your app expects the user to be logged in before myMethod is invoked but for some reason he isn’t.

That means the real bug occurred elsewhere probably in the area of code where callSerially() → myClass.myMethod(; was called. Lets say you looked over the entire body of code and you have suspects but can’t tell which part is at fault. Narrowing this down would help…​

That’s where Display.setEnableAsyncStackTraces() comes in. When set to true it creates a "fake" exception for every callSerially if there’s a "real" exception thrown within the callSerially it uses this "fake" one as the cause. That means you will be able to see the cause for a specific bug when this is enabled.

Notice that this API is potentially prohibitive in terms of performance. As such we recommend that people don’t turn this on by default. You can include this as a user configuration or use it in debug builds.

Share this Post:

Posted by Shai Almog

Shai is the co-founder of Codename One. He's been a professional programmer for over 25 years. During that time he has worked with dozens of companies including Sun Microsystems.
For more follow Shai on Twitter & github.