我使用JODConverter将.xls和.ppt转换为.pdf格式。为此,我有一些代码像Java中的奇怪错误try-catch-finally
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块。 困惑
尝试捕获'Throwable',并观看stacktrace,也许conection.connect()抛出一个错误(这也延伸Throwable)。 – amit
也许你有'java.lang.Error'? – wjans
为什么不附加调试器,看看会发生什么?我的猜测是你缺少一个类/库,所以'connection.connect()'产生一个'ClassNotFoundError'。这不会被当作一个例外,但它会让你进入'finally'子句。 –