参见英文答案 >
How to catch an Exception from a thread 14个
我正在使用一个创建自己的线程的库,它会抛出异常.我怎么能抓住那个例外?在下面标记的行上抛出异常:
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());
}
}