Try-catch-finally and then again a try catch

Write a SQLUtils class that contains static closeQuietly methods that catch and log such exceptions, then use as appropriate. You’ll end up with something that reads like this: public class SQLUtils { private static Log log = LogFactory.getLog(SQLUtils.class); public static void closeQuietly(Connection connection) { try { if (connection != null) { connection.close(); } } catch … Read more

What are the circumstances under which a finally {} block will NOT execute?

If you call System.exit() the program exits immediately without finally being called. A JVM Crash e.g. Segmentation Fault, will also prevent finally being called. i.e. the JVM stops immediately at this point and produces a crash report. An infinite loop would also prevent a finally being called. The finally block is always called when a … Read more