Exceptions are a super GOTO. Rather than allowing you to jump anywhere in the position of the procedure, they allow you to teleport up the call stack to any number of handlers.
Wrong. Exceptions, unlike GOTOs, can't jump straight into a loop or any construct that has a local state. In fact, exceptions never break local states, and that's their beauty.
The best proof that exceptions don't break anything is that you can always represent a throw/catch cycle with IF's, RETURN's, possibly also subroutines, but there will be no GOTOs. You will have equivalent functionality, except the code will be a bit bloated and less readable.
Indeed. Rather, exceptions are a super "break", not a goto.
I do think there's some reasonable insight in this article. Lots of folks get very confused about the difference between an exception and an "error", or "return value", and produce code that mixes the concepts in strange and terrible ways.
Nonetheless, misuse of a tool isn't really an indictment of the tool. Certainly good exception handling can make some designs much, much cleaner than they would be with traditional handling.
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'.
In 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.
ctor
try {
dostuff
} catch 1 {
blahblah
} catch 2 {
aoeuaoeuaoeu
} finally {
dtor
}
//why not put the dtor here and just leave off the finally block completely?
Wrong. Exceptions, unlike GOTOs, can't jump straight into a loop or any construct that has a local state. In fact, exceptions never break local states, and that's their beauty.
The best proof that exceptions don't break anything is that you can always represent a throw/catch cycle with IF's, RETURN's, possibly also subroutines, but there will be no GOTOs. You will have equivalent functionality, except the code will be a bit bloated and less readable.