我正在使用 JODConverter 将 .xls 和 .ppt 转换为 .pdf 格式。为此,我有类似的代码
try{
//do something
System.out.println("connecting to open office");
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
System.out.println("connection object created");
connection.connect();
System.out.println("connection to open office successful");
//do something
if(!successful)
throw new FileNotFoundException();
}catch(Exception e){
System.out.println("hello here");
System.out.println("Caught Exception while converting to PDF ");
LOGGER.error("Error in converting media" + e.getMessage());
throw new MediaConversionFailedException();
}finally{
decode_pdf.closePdfFile();
System.out.println("coming in finally");
//do something here
}
我的输出:
connecting to open office
connection object created
coming in finally
附言方法的返回类型为 void
这怎么可能?即使 connection.connect() 中有问题,它也会出现在 catch block 中。 困惑
最佳答案
可能抛出了一个错误。这仍然会导致 try block 未完成,忽略 catch 异常 block 并调用 finally block 。
关于java - Java try-catch-finally 中的奇怪错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6517057/