のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

thread exiting with uncaught exception

   1563 static void threadExitUncaughtException(Thread* self, Object* group)
   1564 {
   1565     Object* exception;
   1566     Object* handlerObj;
   1567     Method* uncaughtHandler;
   1568 
   1569     ALOGW("threadid=%d: thread exiting with uncaught exception (group=%p)",
   1570         self->threadId, group);
   1571     assert(group != NULL);
   1572 
   1573     /*
   1574      * Get a pointer to the exception, then clear out the one in the
   1575      * thread.  We don't want to have it set when executing interpreted code.
   1576      */
   1577     exception = dvmGetException(self);
   1578     assert(exception != NULL);
   1579     dvmAddTrackedAlloc(exception, self);
   1580     dvmClearException(self);
   1581 
   1582     /*
   1583      * Get the Thread's "uncaughtHandler" object.  Use it if non-NULL;
   1584      * else use "group" (which is an instance of UncaughtExceptionHandler).
   1585      * The ThreadGroup will handle it directly or call the default
   1586      * uncaught exception handler.
   1587      */
   1588     handlerObj = dvmGetFieldObject(self->threadObj,
   1589             gDvm.offJavaLangThread_uncaughtHandler);
   1590     if (handlerObj == NULL)
   1591         handlerObj = group;
   1592 
   1593     /*
   1594      * Find the "uncaughtException" method in this object.  The method
   1595      * was declared in the Thread.UncaughtExceptionHandler interface.
   1596      */
   1597     uncaughtHandler = dvmFindVirtualMethodHierByDescriptor(handlerObj->clazz,
   1598             "uncaughtException", "(Ljava/lang/Thread;Ljava/lang/Throwable;)V");
   1599 
   1600     if (uncaughtHandler != NULL) {
   1601         //ALOGI("+++ calling %s.uncaughtException",
   1602         //     handlerObj->clazz->descriptor);
   1603         JValue unused;
   1604         dvmCallMethod(self, uncaughtHandler, handlerObj, &unused,
   1605             self->threadObj, exception);
   1606     } else {
   1607         /* should be impossible, but handle it anyway */
   1608         ALOGW("WARNING: no 'uncaughtException' method in class %s",
   1609             handlerObj->clazz->descriptor);
   1610         dvmSetException(self, exception);
   1611         dvmLogExceptionStackTrace();
   1612     }
   1613 
   1614     /* if the uncaught handler threw, clear it */
   1615     dvmClearException(self);
   1616 
   1617     dvmReleaseTrackedAlloc(exception, self);
   1618 
   1619     /* Remove this thread's suspendCount from global suspendCount sum */
   1620     lockThreadSuspendCount();
   1621     dvmAddToSuspendCounts(self, -self->suspendCount, 0);
   1622     unlockThreadSuspendCount();
   1623 }