2 ms·
The problem with exceptions is that most developers using them don't use them well, which does kind of mean that they should be avoided if you're not sure you n
by IsaacSchlueter 18y ago
The problem with exceptions is that most developers using them don't use them well, which does kind of mean that they should be avoided if you're not sure you need it. But I don't think that they have no place in running code. (Since I write mostly Javascript, try/catch is so expensive that it's usually not worth it, especially if you build your site so that it works when the JS doesn't, which is just good practice.)
I recently came across something like this, which struck me as a horrendous abuse of "exception" handling:
// drastically simplified so as to not make anyone nauseous/crazy:
try {
$x = doSomething();
doSomethingElse($x);
if (!$x->foo) {
$x->foo = "bar";
throw new NoFooException($x);
}
doSomeMoreThings($x);
} catch NoFooException {
handleNoFooCase($x);
}
Not 10 lines later, in the same function:
do {
...bunch of code.
if (!$x) {
break;
}
bunch more code.
if (!$y) {
break;
}
bunch more code.
} while(false);
followed by new fewer than 3 other "clever" control constructs.
Frankly, GOTOs would have been easier to follow.