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

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

本文介绍了如何捕获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 对象,你可以尝试设置一个。
看看。

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中另一个线程抛出的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 14:32