UncaughtExceptionHandler 在catch之后线程会自动结束,需要重新开启一个线程
mHandlerThread = HandlerThread("test",Process.THREAD_PRIORITY_BACKGROUND)
mHandlerThread.uncaughtExceptionHandler = object : Thread.UncaughtExceptionHandler {
override fun uncaughtException(t: Thread, e: Throwable) {
if (e is SQLException) {
mHandlerThread = HandlerThread("test",Process.THREAD_PRIORITY_BACKGROUND)
mHandlerThread.uncaughtExceptionHandler = this
mHandlerThread.start()
} else {
throw e
}
}
}
文章讲述了在Java中,当UncaughtExceptionHandler捕获到SQLException时,如何重新创建一个新的HandlerThread并设置其未捕获异常处理器,确保线程不会终止。
409





