如何捕获Java中另一个线程抛出的异常?

编程入门 行业动态 更新时间:2024-10-23 09:21:51
本文介绍了如何捕获Java中另一个线程抛出的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用一个创建自己的线程的库,它会抛出异常。我怎么能抓住那个例外?在下面标记的行上抛出异常:

I'm using a library that creates its own thread and it throws an exception. How can I catch that exception? The exception is thrown on the line marked below:

ResourceDescriptor rd = new ResourceDescriptor(); rd.setWsType(ResourceDescriptor.TYPE_FOLDER); fullUri += "/" + token; System.out.println(fullUri); // >>> EXCEPTION THROWN ON THE FOLLOWING LINE <<< rd.setUriString(fullUri.replaceAll("_", "")); try{ rd = server.getWSClient().get(rd, null); }catch(Exception e){ if(e.getMessage().contains("resource was not found")){ this.addFolder(fullUri, label, false); System.out.println("Folder does not exist, will be added now."); }else{ System.out.println("Error Messages: " + e.getMessage()); } }

推荐答案

如果你无法理解它可能会帮助你:

If you can not catch it maybe that helps you:

如果你有 Thread 对象,你可以尝试设置一个 UncaughtExceptionHandler 。 看看 Thread.setUncaughtExceptionHandler(...)。

If you have the Thread object you can try to set a UncaughtExceptionHandler. Take a look at Thread.setUncaughtExceptionHandler(...).

向我们提供有关您使用的库以及如何使用它的更多详细信息。

Give us some more detail about the library you use and how you use it.

更多推荐

如何捕获Java中另一个线程抛出的异常?

本文发布于:2023-11-11 23:35:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579851.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   抛出   异常   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!