在我正在开发的应用中,我使用Google Analytics跟踪未捕获的异常,如下所示:
#include <stdio.h>
#define MAXLINE 256
int main () {
int c, ndigit[10], i, d, e;
char str[MAXLINE];
while ((c = getchar()) != EOF) {
if (c >= '0' && c <= '9')
++ndigit[c - '0'];}
for (i = 0; i <= 9; i++) {
for (d = 0; d < ndigit[i]; d++)
str[d] = '*';
str[d] = '\0';
printf("%d: %s\n",i,str);
for (e = 0; e <= MAXLINE; e++)
str[e] = '\0';
}
return 0;
}
这是处理程序, AnalyticsExceptionHandler 类:
// ...after setting up Google Analytics...
Thread.setDefaultUncaughtExceptionHandler(new AnalyticsExceptionHandler(Thread.getDefaultUncaughtExceptionHandler()));
事情是,应用程序从未真正崩溃,它只是冻结。如果我删除 setDefaultUncaughtExceptionHandler()行,则应用程序会正常崩溃。
我是否在上面的代码中将错误传递给以前的默认处理程序?
答案 0 :(得分:0)
为什么不重新抛出异常?
public void uncaughtException(Thread t, Throwable e)
{
// ...track and send the exception to Google Analytics...
_defaultHandlerRef.uncaughtException(t, e);
throw e;
}