Five Things I Love About Spring
Subject:   Bug in "The Old Way" Code
Date:   2005-11-13 08:29:41
From:   DavidPeterson
Your code:

public List getBikesOldWay() throws Exception {
List bikes = null;
Session s = null;
try {
s = mySessionFactory.openSession( );
bikes = s.find("from Bike");
}catch (Exception ex) {
//handle exception gracefully
}finally {
s.close( );
return bikes;

This will throw a NullPointerException in the finally block if the session factory throws an exception when opening a session, i.e. it will conceal the true exception.

Is this how Spring does it too?