4 ms·
if you have to use C++ without exceptions (console video games), then goto is much needed to handle exceptional situations locally. For example there would be l
by malkia 15y ago
if you have to use C++ without exceptions (console video games), then goto is much needed to handle exceptional situations locally. For example there would be label "fail:;" or "out:;" at the end of the function, where release of resource would happen, and you would "goto" to it, rather than releasing the resources in multiple exceptional places and return from there.
- brnstz 15y agoInteresting. I rarely program in an environment without exceptions, so I haven't had reason to adopt that style. I recall that Linus has advocated the use of goto in the Linux kernel for similar reasons. And the goto version of this code does seem more readable to me: http://kerneltrap.org/node/553/2131 http://kerneltrap.org/node/553/2131
- cpeterso 15y agoIf you are using C++ (even without exceptions), then RAII (Resource Acquisition Is Initialization) with resources freed in local variables' destructors is a better solution.
- __rkaup__ 15y agoWhy don't console games use exceptions?
- to3m 15y agoNo compiler support on one common system. You should be handling every case anyway - by the time the code is done, there are no exceptional situations left ;)