我正在我的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();
一个好主意吗?不是的。无论如何应用程序都会崩溃(但伪造的崩溃报告如预期发送)。是否有另一种实现我想要的方式?