主动处理
runnable中通过try…catch进行处理
public void run() {
Throwable thrown = null;
try {
...
} catch (Throwable e) {
...
thrown = e
} finally {
// 线程退出的处理
threadExited(this, thrown);
}
}
通过UncaughtExceptionHandler处理
方法:
通过set方法设置异常处理器
Thread thread = new Thread();
thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e