Raise exception in caller's stack frame

Paul Prescod paulp at ActiveState.com
Thu Mar 15 11:49:15 EST 2001


Paul Prescod wrote:
> 
> Can someone remind me how to raise an exception in my caller's stack
> frame? I'll add it as a recipe to the Python cookbook (or you can do it
> if you want the fame and...well, just fame).

I don't know if this made sense to anyone after I posted it in the
middle of the night. What I want to do is throw a exception but not have
*my* function body in the stack trace:

def throwException(condition):
    if condition:
        raise AssertionError in parent_stackframe

def foo():
    throwException(i==1)

I'm thinking that the trick has something to do with setting up a trace
function or maybe it just isn't possible. I've done similar tricks
before but perhaps not this particular one...

-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.activestate.com/pythoncookbook




More information about the Python-list mailing list