Robust code cries often and loudly as soon as something is not right. It does not cower away in corners of obscurity hoping that no one will notice, until one day, shit hits the fan.Any serious python code contains proper use of exceptions, errors, and asserts. In fact, I would argue that their presence defines the difference between one-off throwaway scripts and robust library code. Imagine a python interpreter without these facilities. What would the scenario look like? When you write to a non-existent or write-protected file, instead of the sys module alerting you to the fact, you'd get .. nothing. Not a single sign that your data is gone forever. Exceptions are you friends. They're your canary in the coal mine. They let you know that something is wrong at the point of inception rather than pretending that everything is fine until two months later when your client pops a vein because their files were not backed-up. Use exceptions to annotate your code. Use them to communicate to your future colleagues that what they're trying to do is seriously wrong. Use them to put yourself in check before you try to modify that class attribute. Exceptions keep you sane.
09 Feb 2010