3

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

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
r15habh
  • 1,468
  • 3
  • 19
  • 31
  • 4
    try to catch `Throwable`, and watch stacktrace, maybe conection.connect() threw an Error (which also extends Throwable). – amit Jun 29 '11 at 07:24
  • Maybe you got a `java.lang.Error`? – wjans Jun 29 '11 at 07:24
  • 1
    Why not attach a debugger and see what happens? My guess is that you are missing a class/library, so `connection.connect()` results in a `ClassNotFoundError`. This would not be caught as an exception, but it would get you to the `finally` clause. – Mathias Schwarz Jun 29 '11 at 07:58
  • Spot on. But still jvm s'd tell something about ClassNotFoundError and since the lib was not missing locally there was no way i c'd have detected that error. – r15habh Jun 29 '11 at 09:09

4 Answers4

5

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
2

try to catch Throwable, and watch stacktrace, maybe conection.connect() threw an Error (or other custom class which also extends Throwable).

amit
  • 175,853
  • 27
  • 231
  • 333
1

If an error of type Error occurred, or worse, of type Throwable, then your catch handler for Exception wouldn't fire. Is it possible that you're getting some sort of VM error, or OOM, or stack overflow?

If so, this would account for the output you reported.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
0

Depending on the implementation of OpenOfficeConnection Interface various types of throwables can be expected. It is possible that one of those throwables does not extend java.lang.Exception. Try to catch java.lang.Throwable instead

nishu
  • 1,493
  • 11
  • 26