Exception handling in Python 3.x
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Fri Dec 3 19:52:22 EST 2010
On Fri, 03 Dec 2010 17:08:38 +0100, Peter Otten wrote:
> After rereading the original post I still don't get why the workarounds
> provided in those links aren't worth considering.
The first work-around:
http://mail.python.org/pipermail/python-list/2010-October/1258606.html
is unsuitable because it requires the caller to install a custom
excepthook. It would be rude and unacceptable for arbitrary functions to
install hooks, possibly stomping all over the caller's own custom
excepthook. And even if I did, or the caller did, it has the unfortunate
side-effect of suppressing the display of *all* chained exceptions,
including those that come from the bugs in exception handlers.
The second work-around might be worth considering:
http://mail.python.org/pipermail/python-list/2010-October/1259024.html
however it adds unnecessary boilerplate to what should be a simple
try...except...raise block, it obscures the intention of the code. As a
work-around, it might be worth considering, but it's hardly elegant and
it could very well be a fluke of the implementation rather than a
guaranteed promise of the language.
In the absence of a supported way to suppress exception chaining, I'm
leaning towards my original work-around: set a flag in the except block,
then raise the exception once I leave the block.
But thanks again for the links.
--
Steven
More information about the Python-list
mailing list