[docs] [issue8652] Minor improvements to the "Handling Exceptions" part of the tutorial

Marien Zwart report at bugs.python.org
Sun Sep 12 13:24:03 CEST 2010

Marien Zwart <m_zwart at 123mail.org> added the comment:

Sorry for forgetting about this for so long.

The attached patch makes the following changes:

Removes the two instances I noticed of treating exception instances as sequences. This no longer works in python 3 and is not very useful in python 2, so best avoided.

Adds a warning explaining ``except FooException, BarException:`` does not do what you might think. I think this is a good warning to have (because you *can* omit those parens in many other places) and it mentions the pre-python 2.6 syntax for "as" by side effect.

There are two things I'm not entirely happy about:

I initially wrote ``print "I/O error({0.errno}): {0.strerror}".format(e)``, but then noticed this string formatting trick is not mentioned in the previous chapter of the tutorial. Dict access (``"{0[foo]}".format(d)``) is, but attribute access is not. Is this worth adding to that chapter, so it can be used here?

Binding an exception instance to a variable (using "as") is explained near the bottom of the section on catching exceptions, well before it is used. Perhaps this could do with a bit of reordering? I felt it better to keep my initial patch more minimal though.

Comments? :)

keywords: +patch
Added file: http://bugs.python.org/file18857/errors.patch

Python tracker <report at bugs.python.org>

More information about the docs mailing list