螺纹与未捕获的异常退出:没有堆栈跟踪堆栈、螺纹、异常

2023-09-06 13:37:49 作者:ヾ尐泡泡°

我的应用程序引起的力接近的地方得到一个致命的异常,在我的LogCat中常用的(和非常丰富的)堆栈跟踪的,而是,我只收到只有以下4行:

My application is causing a force close somewhere but instead of getting a FATAL EXCEPTION with the usual (and very informative) stack trace in my LogCat, I only receive only the following 4 lines:

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

这是在调试模式应用在LogCat中没有过滤器!

This is in DEBUG mode with NO FILTERS applied on the LogCat!

这可能是造成这种现象? 有没有办法告诉是什么导致这个异常?

更新:由于以下@assylias,我已经能够实现:

Update: Thanks to @assylias below, I've been able to implement:

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

其中生产这些添加的行:

Which produced these added lines:

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)

这肯定是更加有用的信息,但现在我挣扎了以下内容:

This is certainly much more useful information, but now I'm struggling with the following:

应用程序不强行关闭了,尽管已呼吁 subclass.uncaughtException()。为什么呢? 什么是所有这些堆栈溢出的含义?我可以做的是如此征税我可怜的Andr​​oid测试设备上? 如何判断哪个部分在我的code原因造成的? The application doesn't force-close now, despite the call to subclass.uncaughtException(). Why? What is the meaning of all those stack overflows? What could I be doing that's so taxing on my poor Android test device? How can I tell which part in my code causes this?

更新: Log.getStackTraceString(paramThrowable); 实际上并没有打印任何东西。我收到额外的印刷是从假 subclass.uncaughtException(paramThread,paramThrowable);记录完整的堆栈跟踪的正确方法是使用 Log.e(TAG,uncaughtException,抛出)。

Update: Log.getStackTraceString(paramThrowable); wasn't actually printing anything. The extra print that I received was from the bogus subclass.uncaughtException(paramThread, paramThrowable); The right way of logging the full stack trace is by using Log.e(TAG, "uncaughtException", throwable).

现在剩下的唯一的问题是如何重新抛出异常?只是做了扔paramThrowable

The only question remaining now is how do I re-throw the exception? Just do a throw paramThrowable?

回答我的最后一个问题:Eclipse将不会让我抛不与try / catch语句,这使我明白,我想是不是再掷但 killProcess()。问题解决了。

Answering my last question: Eclipse won't let me throw without surrounding with try/catch, which led me to understand that what I want is not a re-throw but a killProcess(). Problem solved.

推荐答案

您可以设置您的应用程序的开始默认的未捕获异常处理程序和记录中的一些数据存在(例如下面是使用Java记录,但容易转来安卓):

You could set a default uncaught exception handler at the beginning of your app and log some data in there (example below is using a java logger but easy to transpose to 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);
    }
}