5 ms·
> No matter how you slice it, exceptions are still a goto under the covers. This is a poor argument; the same could be said for almost all control flow stateme
by Ace17 9y ago
> No matter how you slice it, exceptions are still a goto under the covers.
This is a poor argument; the same could be said for almost all control flow statements: if/else, while, for, break, continue, (early)return ... they're all implemented using "goto under the covers". Moreover, lots of C programs use goto to do their error handling!
Seeing "throw" statements as gotos misses the point: you can't really create spaghetti control flow using "throw" statements.
Instead, you can see them as "return on steroids".
It's true that "try-catch" makes it hard to know where your code is gonna "jump" ; but that's the point : as the "thrower", you don't have to know, and you don't /want/ to know.
Think about the standard libraries for Java, C#, Python, D ... they don't have this luxury.
If when using "throw", you're wondering "where's the catch", then you /probably/ have a design issue.
- smitherfield 9y agoAgreed. Minor quibble: >This is a poor argument; the same could be said for almost all control flow statements: if/else It's technically possible to implement if/else (and loop conditions) with unconditional jumps and offsets, but for reasonable instruction sets (that support conditional jumps) they won't be "goto under the covers."