6 ms·
> ...exceptions-as-control-flow abuse or even the assertion that exceptions are really just a type safe version of goto. I was recently telling someone about a
by dehrmann 7y ago
> ...exceptions-as-control-flow abuse or even the assertion that exceptions are really just a type safe version of goto.
I was recently telling someone about a little-known Java feature that I wish C would adopt. Goto is common in C exception handling code because the alternative is unworkably messy. Java has named code blocks that you can break out of, so they're not gogo, but they're also not exception abuse.
initBlock: {
if (fail) { break initBlock; }
doSomething();
}
- ferzul 7y agoIn that case, in javascript, i always just write a function. { init() } const init = () => { if (fail) return doSomething() } (there's a few other cases i introduce functions for syntactic reasons in js - e.g. at the expense of a const funtion, i can convert a let to a const - but i have always found this improves the code on standard readability guides)