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

Wrong line number on stack trace

Yes, this is a limitation in the exception handling logic. If a method contains more than one throw statement that throws an exception then you’ll get the line number of the last one that threw. This example code reproduces this behavior: using System; class Program { static void Main(string[] args) { try { Test(); } … Read more

Throws or try-catch

catch an exception only if you can handle it in a meaningful way declare throwing the exception upward if it is to be handled by the consumer of the current method throw exceptions if they are caused by the input parameters (but these are more often unchecked)