2016-11-21 38 views
0

在以下代碼中,我在已發佈的應用程序中獲取異常數據。此應用程序未在調試模式下運行 - 它在許多手機上作爲發佈的應用程序運行。UncaughtExceptionHandler問題

我在這裏工作得很好。它將異常數據放入共享內存中,我在下次運行應用程序時發送給自己。我的問題是,我得到的數據不是非常有用。這是產生的。 。 。

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); 
     } 
}; 

這並沒有告訴我很多。無論如何,我可以得到一個堆棧跟蹤?任何能夠告訴我程序中哪裏出錯的事情? 謝謝, 院長

+0

http://stackoverflow.com/questions/1149703/how-can-i-convert-a-stack-trace-to-a-string,雖然恕我直言,它會是在這裏採用現有的解決方案要好得多,比如[ACRA](http://acra.ch/)。 – CommonsWare

回答

0

糟糕。發佈到即將發佈。找出答案...

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); 
     } 
}; 
相關問題