4 ms·
Exceptions have a major advantage not mentioned by the OP. In code, errors usually happen several stack frames away from the code that knows how to recover. Th
by jakevoytko 15y ago
Exceptions have a major advantage not mentioned by the OP.
In code, errors usually happen several stack frames away from the code that knows how to recover. The network can't transmit data because a remote computer doesn't respond[0], so it passes an error to the network library, which passes an error to an RPC dispatcher, which passes an error to the high-level RPC interface, which finally produces an error at the site of your RPC call, where you can decide what to do.
If you don't have exceptions, you must write all of this error handling code yourself. Plus, if you need to pass the error higher than the call site to make a good decision, you must write that too. However, if you have exceptions, you can avoid writing most of the error passing code, and you can group error handling logic in the same place. You get more flexibility in structuring and refactoring your code, in exchange for encountering problems when things unexpectedly go out of scope.
[0] This certainly passes my 'exceptional circumstance' threshold, since success is no longer possible.