When should I use code snippet A instead of snippet B (i.e. what are the benefits of using snippet A)?:
Snippet A:
try {
// codeblock A
}
catch (Exception ex) {
// codeblock B
}
finally {
//codeblock C
}
Snippet B:
try {
// codeblock A
}
catch (Exception ex) {
// codeblock B
}
//codeblock C
Use a finally block if you have code that must execute regardless of whether or not an exception is thrown.
Cleaning up scarce resources like database connections are a good example.