In a language which uses exceptions to signal errors, I want to call some third-party code and, if it fails, run fallback code instead. For example:
try:
result = third_party.fast_calculation()
catch:
result = slower_calculation()
In my experience, it is very rare to know all of the exceptions that could be thrown by the third-party code. Therefore I cannot list these exceptions in the catch
clause. On the other hand, I am frequently advised not to catch
every possible exception.
How should I write the catch
clause in this situation?