0

In the following code I am obtaining exception data in an released app. This app is not running in debug mode - it is running as a released app on lots of phones.

What I have here works just fine. It puts exception data into shared memory which I mail to myself the next time the app runs. My problem is that the data I get isn't terribly useful. This is what is produced . . .

divide by zero StackTrace= [Ljava.lang.StackTraceElement;@7734137 Cause= null ex= java.lang.ArithmeticException: divide by zero

private Thread.UncaughtExceptionHandler onBlooey = new Thread.UncaughtExceptionHandler() {
        public void uncaughtException(Thread thread, Throwable ex) {
                putPref("storedexception", "Exception: " + ex);
        }
};   

This doesn't tell me much. Is there anyway I can get a stacktrace? Anything that would tell me where in the program the error is occurring? Thanks, Dean

Dean Blakely
  • 3,535
  • 11
  • 51
  • 83
  • http://stackoverflow.com/questions/1149703/how-can-i-convert-a-stack-trace-to-a-string, though IMHO it would be far better for you to adopt an existing solution here, such as [ACRA](http://acra.ch/). – CommonsWare Nov 21 '16 at 23:03

1 Answers1

0

Oops. Posted to soon. Figured out the answer...

    private Thread.UncaughtExceptionHandler onBlooey = new Thread.UncaughtExceptionHandler() {
        public void uncaughtException(Thread thread, Throwable ex) {
                // quickly store the exception info and mail it to me nextime on startup
            debugLog("found uncaught exception: " + ex, true);
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            ex.printStackTrace(pw);
            String st = "";
            st = sw.toString(); // stack trace as a string
            putPref("storedexception", "Exception: " + ex + " stacktrace: " + st);
        }
}; 
Dean Blakely
  • 3,535
  • 11
  • 51
  • 83