@Alexis de Torquemada said:
@Cyresse said:Yeech, a try without an except/catch? Bad. Bad.Try is to catch exceptions, right? I think someone got carried away with "finally"
No, it makes sense in languages that don't have deterministic destruction (rsp. "disposal" as in C#).
Yes, but this is in Java and not some other language. In Java, the only reason to use a try/finally is to guarantee code is executed [i]in the face of an exception[/i] regardless of how that exception is handled. The posted code had nothing to do with an exception and was a good example of abusing try/finally.
I wouldn't say try is for catching exceptiosn, however, as it's entirely possible you don't want to catch the exception but you do want to guarantee code is executed despite one. A classic example is
<FONT face="Courier New">try {</FONT>
<FONT face="Courier New"> lock.lock();</FONT>
<FONT face="Courier New">} finally {</FONT>
<FONT face="Courier New"> lock.unlock();</FONT>
<FONT face="Courier New">}</FONT>
without which an unchecked exception would cause the lock to never be released.