Reraising exceptions "intact"

Erik Max Francis max at alcyone.com
Fri Jun 8 11:58:54 EDT 2001


Jesus Cea Avion wrote:

> I'd like to know how to reraise a "catched" exception, intact:
> 
> while 1
>   try :
>     func()
>   except exceptions.KeyboardInterrupt :
>     raise exceptions.KeyboardInterrupt
>   except :
>     pass
> 
> Here we keep "func" running except if the user press CONTROL+C. But in
> this case I'd like to see a traceback for the original interrupt
> point,
> not the "artificial" "raise".

In an except block, just use `raise' to reraise the caught error:

    while 1:
        try:
            func()
        except exceptions.KeyboardInterrupt:
            raise
        except:
            pass

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Honesty has nothing to hide
\__/ Joi
    Esperanto reference / http://mirror/alcyone/max/lang/esperanto/
 An Esperanto reference for English speakers.



More information about the Python-list mailing list