Question on try/except

Patrick Maupin pmaupin at gmail.com
Tue Aug 8 01:05:00 EDT 2006


Kirk McDonald wrote:
> Dan wrote:
> > Is there some particular use in catching an exception and immediately
> > re-raising it?  Why catch it at all?
>
> All I can think of is that it changes the traceback to point to the
> re-raise and not the original raise.

I've used this technique before.  It is very useful where (as in the
original re example) recursion might cause a large traceback, and the
error is probably caused by the caller's code.  Using this technique
can keep the visible portion of the traceback relevant to the problem
at hand.

Regards,
Pat




More information about the Python-list mailing list