It's not equivalent, because of the reason you already gave: The exception is still thrown in the first case. And there might be reasons, where you exactly want such a behavior: Close resources, e.g. Streams in finally
block, but throw the exception out of the enclosing method, to handle it else where.
Btw., you can also "abuse" try
-finally
constructs, in case no exception is expected at all:
private StringBuilder buffer = new StringBuilder();
private String getBuffer() {
try {
// return current String content of the buffer
return buffer.toString();
} finally {
// assign a new StringBuilder, before method returns
buffer = new StringBuilder();
}
}