@Chin Boon As a general practice, you should do the "close()" operation inside "finally" block, so that you ensure that it always gets executed. This code block can then itself have its own try - catch block.
–
NapteJan 18 '12 at 13:59

you still get pretty much the same info. There are some minute differences:

in the first case, the line getSession().close(); will still be called even if getSession().getTransaction().rollback(); throws an exception, while in my example it will not. The proper way to handle this however is to use a finally block if you want that .close() line to be called no matter what.

no need for a finally, you'd presumably want to catch any exceptions thrown during the close() operation too..
–
NimJan 18 '12 at 13:01

You'll still need to use a try-catch in the finally block though. This just ends up making the method more verbose.
–
mreJan 18 '12 at 13:02

Not really, if your last .close() operation thows an exception you don't really want to catch that as there's no real good way to recover from it. I agree however that it's just a matter of taste.
–
Shivan DragonJan 18 '12 at 13:03

1

@AndreiBodnarescu, My comment was made with the assumption that OP didn't want the method to throw an exception.
–
mreJan 18 '12 at 13:05

The reason is independence between these parts. Both parts may fail independently. (And handled independently as well). A fail of 'rollback' invocation won't prevent execution of 'close' statement, as opposite to a single try-catch block approach for this case.