Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird bug in Java try-catch-finally

I'm using JODConverter to convert .xls and .ppt to .pdf format. For this i have code something like

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
}

My Output :

connecting to open office
connection object created
coming in finally

P.S. return type of method is void

How is it possible ? Even if there is some problem in connection.connect(), it s'd come in catch block. confused

like image 746
r15habh Avatar asked Jul 24 '26 22:07

r15habh


1 Answers

Perhaps an Error was thrown. This would still result in the try block not being completed, the catch Exception block ignored and the finally block being called.

like image 146
Peter Lawrey Avatar answered Jul 26 '26 14:07

Peter Lawrey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!