马克-to-win:接着我们看子线程如何捕获主线程的异常
例:1.5.4_2
import java.lang.Thread.UncaughtExceptionHandler;
class ThreadMark_to_win extends Thread {
Thread mainT;
Test test;
ThreadMark_to_win(Thread t1,Test t2)
{
mainT = t1;
test=t2;
mainT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
System.out.println("在子程序处理呢, 传进来的参数是"+test.name+" "+t.getName()+" "+ e.getMessage());
}
});
}
public void run()
{
for(int i=0;i<3;i++)
{
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
System.out.println("在子线程"+i);
}
}
}
public class Test {
String name="马克-to-win在主线程";
public static void main(String[] args) {
Thread mainT = Thread.currentThread();
Test t=new Test();
继续阅读与本文标签相同的文章
python了解字符编码的知识储备
-
CMU 15-721 16-服务器端的逻辑执行 Server -side Logic Execution
2026-05-18栏目: 教程
-
谷歌搜索广告出价方式
2026-05-18栏目: 教程
-
印度5G建设即将开始,是屈服于美国的施压,还是选择跟华为合作?
2026-05-18栏目: 教程
-
系列文章:云原生Kubernetes日志落地方案
2026-05-18栏目: 教程
-
QQ浏览器正孵化“用户增长团队”,解读中国浏览器行业发展趋势
2026-05-18栏目: 教程
