Defensive programming is not fixing bugs with more features, quite the opposite: it is failing hard when a condition does not hold.
Defensive programming is not fixing bugs with more features, quite the opposite: it is failing hard when a condition does not hold.
If it shouldn't throw, don't try to catch... That is an unexpected failure that needs to be understood.
Thank you for standing up for confident programming! (We could make this a new term if we wanted to :D)
EDIT: Wait, maybe there's a better term than confident programming already... I would appreciate some input if someone sees this.
The best solution is, as always, context and resource dependant.
At the same time, you really should try to validate inputs. The idea being that most exceptions caught should be of the form 'Input was invalid'. Rather than 'function crashed'.
> without an understanding of IF it should and WHY it might
rocqua explains it best - the API handler is an "input" to the overall system. That input may be "invalid" in that it fails to handle its own errors. In that case, you should catch a general exception rather than crashing. In this case, you know that it might raise an error, why it might raise an error, and that it's OK to ignore (well, log/alert/whatever.)
The situation I was responding to is very different - it's basically suggesting rather understand what the API you're invoking may be trying to tell you, just try/catch anything it throws and ignore it if you didn't expect it.
On the other hand, a system where damage is prevented in some ways and assumed not to happen in others is already an overly complex construction of interacting systems. Switching to an invulnerability flag could simplify the system.