Search code examples
javaexceptiontry-catch-finally

How we make Java Code to jump to finally


Here's the piece of code I am seeing

 1 session s=null; 
 2 try{
 3    s= SessionCreator.createSession();
 4    System.out.println("Session Created");
 5    s.validate(); 
 6 }catch (Exception e){
 7    e.printStackTrace(); 
 8 }finally{
 9    s.close();
10 }

Debugger jumps from line 3 to line 9, How is this possible ? Neither 4,5 nor 7 was executed. This puzzles me. line 3 is a vendor code, So I don't know what is happening. Any clues ?


Solution

  • If neither line 4 nor line 7 get executed, maybe (and I stress the "maybe" because I don't know the Java exception mechanism very in-depth) line 3 is not throwing an Exception object, but an Error or a Throwable.