Timeline for Why use try … finally without a catch clause?
Current License: CC BY-SA 3.0
4 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 4, 2016 at 16:32 | comment | added | Wtrmute | You can, but if l.lock() fails, the finally block will still run if l.lock() is inside the try block. If you do it like gnat suggests, the finally block will only run when we know that the lock was acquired. | |
| Jun 25, 2015 at 18:58 | comment | added | gnat | technically, you can. I didn't put it there because semantically, it makes less sense. try in this snippet is intended to wrap resource access, why polluting it with something unrelated to that | |
| Jun 25, 2015 at 18:55 | comment | added | RMachnik | Can I put l.lock() inside try? try{ l.lock(); }finally{l.unlock();} | |
| Feb 15, 2012 at 15:59 | history | answered | gnat | CC BY-SA 3.0 |