views:

1552

answers:

4

Is there a way to print a stack trace to screen in j2me? I have code that looks like the following, which works fine for displaying the message, but can't figure out any way to get ahold of the stack trace.

        try {
      throw new RuntimeException("This is bad stuff!");
     } catch (Exception e ) {
      mainForm.append("Exception: " + e.getMessage());
     }

Calling e.printStackTrace() sends it somewhere that I can't find...

+2  A: 

see this article: http://lwuit.blogspot.com/2008/12/redirecting-output-on-s60-devices.html

too bad there is no System.setErr(PrintWriter) or Thread.getStackTrace()

I don't think there is a (generic) solution for this problem

Somatik
This is totally awesome! I happened to be using an S60 device, so this was perfect
Cory
A: 

No, you can't. Stack trace is always printed to System.err and there is no way in CLDC to redirect System.err to somewhere else.

Malcolm
+1  A: 

EVen in CLDC 1.1 this does not exist.. hope Sun includes Rediction of error and out stream in future versions.. It is very essential of logging/debuging..

Regards, Raja Nagendra Kumar

A: 

I've created a tool that can be used to log proper stack traces also in CLDC. Check it out at http://jarrut.sourceforge.net. It's still very new and it might have some rough edges, but it works for me and I couldn't imagine developing MIDlets without it anymore. Best way to use it is to combine it with microlog.

Olli Kallioinen