2 ms·
You mean, how can that be replaced with ordinary operators? If you have multiple return's, move your 'finally' block to a separate function and call it before e
by mojuba 18y ago
You mean, how can that be replaced with ordinary operators? If you have multiple return's, move your 'finally' block to a separate function and call it before every 'return'.
- AndyKelley 18y agoI have never been able to use the finally block. I have yet to see an example where you would want to use it.
- mojuba 18y agoIn languages with implicit construction/destruction facility, like C++, you'd probably live happily without the finally block. There are however situations in C++ when you want to create a class with ctor/dtor only to make sure some block is executed when going out of scope, no matter how. That dtor would be your finally block.
- gaius 18y agoIndeed - once I discovered __del__ in Python, I immediately started to do it that way instead.
- AndyKelley 18y agoctor try { dostuff } catch 1 { blahblah } catch 2 { aoeuaoeuaoeu } finally { dtor } //why not put the dtor here and just leave off the finally block completely?
- dhouston 18y agoany kind of cleanup -- especially releasing locks/other shared resources, and also closing sockets, files, memory, etc.