[Python-3000] self-contained exceptions
Phillip J. Eby
pje at telecommunity.com
Wed Jan 10 15:28:03 CET 2007
At 10:00 PM 1/9/2007 -0800, Josiah Carlson wrote:
>I know that one of the points of all of this is so that the name that
>the exc_info() stuff gets in the local scope doesn't propagate past the
>except clause,
That is the *entire* point of this, actualy. :) (Well, the "as" change
was supposed to happen anyway.)
>but I can't help feeling as if removing the name isn't a
>little overenthusiastic.
>>Here's an alternate semantic...
>> try:
> ...
> except <exceptions> as <name>:
> <body>
>>... would become ...
>> try:
> try:
> ...
> except <exceptions>:
> <name> = sys.exc_info()
> <body>
> finally:
> if '<name>' in locals():
> <name> = None
Please provide what you'd put in the reference manual as an explanation of
this behavior. (Remember: if the implementation is hard to explain...)
>The benefit to the above is that the name only disappears from the
>namespace if the user deletes it, otherwise the name is bound to None.
Please explain how this is a benefit. By making any use of the name raise
an error, we ensure that you will detect your mistake early, whereas
binding the name to None may allow the value to be passed, stored,
returned, or otherwise used, with the problem not being detected until
later, when it may be much harder to trace back to the source.
In other words, eliminating the error is *not* a benefit here. (Errors
should not pass silently.)
More information about the Python-3000
mailing list