3 ms·
in .NET its illegal - "Control cannot leave the body of a finally clause"
by deekayteez 17y ago
in .NET its illegal - "Control cannot leave the body of a finally clause"
- Jupe 17y agoIt appears MS thought this through. The contrived example is but ONE way a mediocre programmer could really munge this stuff up if the language is not specific about protecting exit points from a finall{} block.
- echaozh 17y agoWhat about throwing exceptions in the finally block? Isn't it an exit point too? When you call non-trivial 3rd party code from your finally block, how do you ensure it doesn't throw? Or what do you do if it does? Indefinitely nested try blocks?
- nollidge 17y agoIndeed. I can't think of a reason as to why any language would even allow it.
- Jach 17y agoI know it's horrible in practice, and I really can't see a valid use for this particular case, but forbidding things like this (or other things like multiple inheritance) just because it can be abused has never seemed like a good idea to me.
- nollidge 17y agoIt's not just that it can be abused, though - every use of it is an abuse. Finally{} is not for decisions and manipulating values and program logic, it's for cleaning up resources.