android-notes / Cockroach

降低Android非必要crash
MIT License
3.25k stars 449 forks source link

如何设置异常白名单 #27

Closed whui-adr closed 5 years ago

whui-adr commented 5 years ago

你好,请教一下,有些异常我不想加入到崩溃保护,如何设置异常白名单呢

android-notes commented 5 years ago

cockraoch 在捕获到异常后会调用 这几个方法:

 protected abstract void onUncaughtExceptionHappened(Thread thread, Throwable throwable);
    protected abstract void onBandageExceptionHappened(Throwable throwable);
    protected void onMayBeBlackScreen(Throwable e) {
    }

你可以在这几个方法里根据throwable的错误堆栈判断是否在白名单里,如果不需要保护的话直接杀进程即可Process.kill() (杀进程前需要先finish所有未finish的act,以免杀进程后反复重启)。你可以在应用启动时等去服务器获取白名单 @whui-adr

whui-adr commented 5 years ago

谢谢