2.9 Avoiding a potential problem with an except: clause
There are some common mistakes in exception handling. These can cause programs to become unresponsive.
One of the mistakes we can make is to use the except: clause with no named exception class to match. There are a few other mistakes that we can make if we’re not cautious about the exceptions we try to handle.
This recipe will show some common exception handling errors that we can avoid.
2.9.1 Getting ready
When code can raise a variety of exceptions, it’s sometimes tempting to try and match as many as possible. Matching too many exception classes can interfere with stopping a misbehaving Python program. We’ll extend the idea of what not to do in this recipe.
2.9.2 How to do it...
We need to avoid using the bare except: clause. Instead, use except Exception: to match the most general kind of exception that an application...