【发布时间】:2014-12-19 14:45:28
【问题描述】:
我在我的 Android 项目中使用了崩溃报告库。激活后,它会对每个未捕获的异常做出反应,并在应用关闭之前创建一个报告。
到目前为止一切都很好,但我想为这件事添加更多“控制”并为非异常创建报告。我的想法是用这种方式定义一个“假”异常:
public final class NonFatalError extends RuntimeException {
private static final long serialVersionUID = -6259026017799110412L;
public NonFatalError(String msg) {
super(msg);
}
}
所以,当我想发送非致命错误消息并创建报告时,我会这样做:
throw new NonFatalError("Warning! A strange thing happened. I report this to the server but I let you continue the job...");
如果从主线程调用,这显然会使应用程序崩溃。所以,我尝试将它放在后台线程上!
new Thread(new Runnable() {
@Override
public void run() {
throw new NotFatalError("Warning! A strange thing happened. I report this to the server but I let you continue the job...");
}
}).start();
一个好主意?不会。应用程序无论如何都会崩溃(但假的崩溃报告会按预期发送)。还有其他方法可以实现我想要的吗?
【问题讨论】:
-
//还有其他方法可以实现我想要的吗?//不,您必须捕获异常以阻止它使应用程序崩溃。
标签: java android exception crash-reports