How to pop the interpreter's stack?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Dec 16 11:23:36 EST 2010


On Thu, 16 Dec 2010 07:29:25 -0800, Ethan Furman wrote:

> Tim Arnold wrote:
>> "Ethan Furman" <ethan at stoneleaf.us> wrote in message
>> news:mailman.4.1292379995.6505.python-list at python.org...
>>> kj wrote:
>>>> The one thing I don't like about this strategy is that the tracebacks
>>>> of exceptions raised during the execution of __pre_spam include one
>>>> unwanted stack level (namely, the one corresponding to __pre_spam
>>>> itself).
[...]
> A decorator was one of the items kj explicity didn't want.  Also, while
> it would have a shallower traceback for exceptions raised during the
> __pre_spam portion, any exceptions raised during spam itself would then
> be one level deeper than desired... while that could be masked by
> catching and (re-?)raising the exception in the decorator, Steven had a
> very good point about why that is a bad idea -- namely, tracebacks
> shouldn't lie about where the error is.


True, very true... but many hours later, it suddenly hit me that what KJ 
was asking for wasn't *necessarily* such a bad idea. My thought is, 
suppose you have a function spam(x) which raises an exception. If it's a 
*bug*, then absolutely you need to see exactly where the error occurred, 
without the traceback being mangled or changed in any way.

But what if the exception is deliberate, part of the function's 
documented behaviour? Then you might want the exception to appear to come 
from the function spam even if it was actually generated inside some 
private sub-routine.

So, with qualifications, I have half changed my mind.



-- 
Steven



More information about the Python-list mailing list