您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

java多线程编程之捕获子线程异常示例

2025/8/17 22:30:14发布19次查看
通过try catch是无法捕获子线程异常的,thread对象提供了setuncaughtexceptionhandler(thread.uncaughtexceptionhandler eh)方法用来获取线程中产生的异常。
package threads; import java.lang.thread.uncaughtexceptionhandler; public class textexception { public static void main(string[] args) { test test = new test(); test.setuncaughtexceptionhandler(new uncaughtexceptionhandler() { public void uncaughtexception(thread t, throwable e) { system.out.println(t.getname() + " : " + e.getmessage()); // todo } }); } public static class test extends thread { public test() { } public void run() { throw new runtimeexception("just a test"); } } }
更多java多线程编程之捕获子线程异常示例。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product