【问题标题】:UncaughtExceptionHandler issueUncaughtExceptionHandler 问题
【发布时间】:2016-11-21 23:01:39
【问题描述】:

在以下代码中,我在已发布的应用程序中获取异常数据。此应用未在调试模式下运行 - 它在许多手机上作为已发布应用运行。

我在这里工作得很好。它将异常数据放入共享内存中,下次应用程序运行时我会邮寄给自己。我的问题是我得到的数据并不是非常有用。这就是产生的。 . .

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

这并没有告诉我太多。无论如何我可以获得堆栈跟踪吗?有什么可以告诉我错误发生在程序的哪个位置? 谢谢, 院长

【问题讨论】:

标签: android stack-trace uncaughtexceptionhandler


【解决方案1】:

哎呀。发布到很快。想出了答案……

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

【讨论】:

    猜你喜欢
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-04
    • 1970-01-01
    相关资源
    最近更新 更多