首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UncaughtExceptionHandler问题

UncaughtExceptionHandler问题
EN

Stack Overflow用户
提问于 2016-11-21 23:01:39
回答 1查看 56关注 0票数 0

在下面的代码中,我在发布的应用程序中获取异常数据。这个应用程序没有在调试模式下运行-它是作为一个发布的应用程序在许多手机上运行。

我这里的一切都很好。它将异常数据放入共享内存中,下次应用程序运行时,我会将这些数据发送给自己。我的问题是,我得到的数据不是很有用。这就是所产生的东西。。。

代码语言:javascript
复制
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);
        }
};   

这并不能说明什么。不管怎么说,我可以得到一个堆栈跟踪吗?任何能告诉我程序中错误发生在哪里的信息?谢谢,迪恩

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-21 23:31:57

糟了。很快就会发到。想出答案..。

代码语言:javascript
复制
    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);
        }
}; 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40730977

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档