On Fri, May 30, 2008 at 7:33 PM, Antoine Pitrou <[EMAIL PROTECTED]> wrote:
> Guido van Rossum <guido <at> python.org> writes:
>> I would be okay as well with restricting bare raise syntactically to
>> appearing only inside an except block, to emphasize the change in
>> semantics that was started when we decided to make the optional
>> variable disappear at the end of the except block.
>>
>> This would render the following code illegal:
>>
>> def f():
>>   try: 1/0
>>   except: pass
>>   raise
>
> But you may want to use bare raise in a function called from an exception
> handler, e.g.:
>
> def handle_exception():
>    if user() == "Albert":
>        # Albert likes his exceptions uncooked
>        raise
>    else:
>        logging.exception("an exception occurred")
>
> def f():
>    try:
>        raise KeyError
>    except:
>        handle_exception()

This can be rewritten to use sys.exc_info(), ie:

def handle_exception():
    if user() == "Albert":
        # Albert likes his exceptions uncooked
        raise sys.exc_info()[1]
    else:
        logging.exception("an exception occurred")

-- 
Adam Olsen, aka Rhamphoryncus
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to