我呀要演示一个用线程组捕获线程异常得例子,同时注意我用了两个匿名类
public class ThreadGroupException {
public static void main(String[] args) {
ThreadGroup threadGroup1 =
new ThreadGroup("线程组名字1") {
public void uncaughtException(Thread t, Throwable e) {
System.out.println(t.getName() + ": "
+ e.getMessage());
}
};
Thread thread1 =
new Thread(threadGroup1,
new Runnable() {
public void run() {
throw new RuntimeException("抛出异常");
}
});
thread1.start();
}
}