|
|
|
|
|
by airstrike
2319 days ago
|
|
One could argue hiding the mess is the whole point of the exception. It allows you think about the problem with a much smaller cognitive load. I'm not suggesting every code with exceptions is good. Just saying that not every exception is bad, and many are indeed great. I can't imagine writing Python without try blocks... |
|
- - - -
Sometimes the problem you're solving really does require a gnarly flow-chart. If that's the case, you're almost certainly better off writing (and documenting!) a state machine instead.
If your control-flow graph is only a little gnarly then representing it with exception syntax is fine IMO (I write Python code too, with exceptions.)
The problem comes when you accidentally create a hidden gnarly graph (as the result of bad design up front, or "drift" over time as a piece of code gets reworked, maybe by multiple people who may not all be privy to the whole history of the design and code, or both) and then forget to do something crucial along some flow of control and you have a hard-to-debug bug.