Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
I’m lumping design tips and gotchas together in this
chapter, because it turns out that the most common gotchas largely
stem from design issues. By and large, exceptions are easy to use in
Python. The real art behind them is in deciding how specific or
general your except clauses should
be and how much code to wrap up in try statements. Let’s address the second of
these concerns first.
In principle, you could wrap every statement in your script in its own try, but that would just be silly (the
try statements would then need to
be wrapped in try statements!).
What to wrap is really a design issue that goes beyond the language
itself, and it will become more apparent with use. But for now, here
are a few rules of thumb: