Question

As I understand, the following 2 examples should do the same thing. Why is the 1st considered better?

1:

try {
  riskyMethod();
}
catch(Exception e) {
  //handle exception
}
finally {
  cleanUp();
}

2:

try {
  riskyMethod();
}
catch(Exception e) {
  //handle exception
}
cleanUp();

EDIT: The example is in Java, but I'm wondering about the concept of a finally block in general, as used in any language

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top