Ete*_*ner 11 java stack-overflow android stack-trace uncaught-exception
我的应用程序导致一个强制关闭某个地方,但我没有在我的LogCat中获得通常(且信息量很大)堆栈跟踪的致命异常,我只收到以下4行:
06-27 07:08:54.546: D/dalvikvm(14351): GC_FOR_MALLOC freed 9923 objects / 657416 bytes in 21ms
06-27 07:08:54.769: W/dalvikvm(14351): threadid=20: thread exiting with uncaught exception (group=0x4001d7f0)
06-27 07:08:54.796: W/dalvikvm(14351): threadid=21: thread exiting with uncaught exception (group=0x4001d7f0)
06-27 07:08:54.796: I/Process(14351): Sending signal. PID: 14351 SIG: 9
Run Code Online (Sandbox Code Playgroud)
这是在DEBUG模式下,LogCat上没有应用过滤器!
更新:感谢下面的@assylias,我已经能够实现:
final UncaughtExceptionHandler subclass = Thread.currentThread().getUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
Log.getStackTraceString(paramThrowable);
subclass.uncaughtException(paramThread, paramThrowable);
}
});
Run Code Online (Sandbox Code Playgroud)
这产生了这些增加的线:
06-27 08:24:47.105: D/dalvikvm(15475): GC_FOR_MALLOC freed 13865 objects / 1435952 bytes in 45ms
06-27 08:24:47.136: I/dalvikvm(15475): threadid=15: stack overflow on call to Ljava/lang/AbstractStringBuilder;.enlargeBuffer:VI
06-27 08:24:47.136: I/dalvikvm(15475): method requires 28+20+20=68 bytes, fp is 0x45209338 (56 left)
06-27 08:24:47.140: I/dalvikvm(15475): expanding stack end (0x45209300 to 0x45209000)
06-27 08:24:47.140: I/dalvikvm(15475): Shrank stack (to 0x45209300, curFrame is 0x4520937c)
06-27 08:24:47.159: I/dalvikvm(15475): threadid=16: stack overflow on call to Ljava/lang/AbstractStringBuilder;.enlargeBuffer:VI
06-27 08:24:47.159: I/dalvikvm(15475): method requires 28+20+20=68 bytes, fp is 0x4520c338 (56 left)
06-27 08:24:47.167: I/dalvikvm(15475): expanding stack end (0x4520c300 to 0x4520c000)
06-27 08:24:47.167: I/dalvikvm(15475): Shrank stack (to 0x4520c300, curFrame is 0x4520c37c)
06-27 08:24:47.175: I/dalvikvm(15475): threadid=17: stack overflow on call to Ljava/lang/AbstractStringBuilder;.enlargeBuffer:VI
06-27 08:24:47.175: I/dalvikvm(15475): method requires 28+20+20=68 bytes, fp is 0x4520f338 (56 left)
06-27 08:24:47.175: I/dalvikvm(15475): expanding stack end (0x4520f300 to 0x4520f000)
06-27 08:24:47.175: I/dalvikvm(15475): Shrank stack (to 0x4520f300, curFrame is 0x4520f37c)
Run Code Online (Sandbox Code Playgroud)
这当然是更有用的信息,但现在我正在努力解决以下问题:
subclass.uncaughtException().为什么?更新: Log.getStackTraceString(paramThrowable);实际上没有打印任何东西.我收到的额外打印来自伪造的 subclass.uncaughtException(paramThread,paramThrowable); 记录完整堆栈跟踪的正确方法是使用Log.e(TAG,"uncaughtException",throwable).
现在唯一的问题是如何重新抛出异常?做一个throw paramThrowable?
回答我的最后一个问题:Eclipse不会让我在没有环绕的情况下抛出try/catch,这让我明白我想要的不是重新抛出而是一个killProcess().问题解决了.
ass*_*ias 18
您可以在应用程序的开头设置默认的未捕获异常处理程序,并在其中记录一些数据(下面的示例使用的是java记录程序,但很容易转换为Android):
private static void setDefaultUncaughtExceptionHandler() {
try {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
logger.error("Uncaught Exception detected in thread {}", t, e);
}
});
} catch (SecurityException e) {
logger.error("Could not set the Default Uncaught Exception Handler", e);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8065 次 |
| 最近记录: |