[Python-ideas] Improving Catching Exceptions
Sven R. Kunze
srkunze at mail.de
Thu Jun 22 16:30:57 EDT 2017
just one note I'd like to dump here.
We usually teach our newbies to catch exceptions as narrowly as
possible, i.e. MyModel.DoesNotExist instead of a plain Exception. This
works out quite well for now but the number of examples continue to grow
where it's not enough.
There are at least three examples I can name off the top of my head:
1) nested StopIteration - PEP 479
2) nested ImportError
3) nested AttributeError
1) is clear. 2) usually can be dealt with by applying the following pattern:
Chris showed how to deal with 3). Catching nested exception is not what
people want many times.
Am I the only one getting the impression that there's a common theme here?
More information about the Python-ideas