[Python-Dev] PEP 409 and the stdlib
Hrvoje Niksic
hrvoje.niksic at avl.com
Tue May 21 15:23:44 CEST 2013
On 05/21/2013 02:57 PM, Serhiy Storchaka wrote:
> 21.05.13 13:05, Hrvoje Niksic написав(ла):
>> On 05/21/2013 11:56 AM, Serhiy Storchaka wrote:
>>> try:
>>> x = d['key']
>>> except KeyError:
>>> x = fallback('key')
>>>
>>> def fallback(key):
>>> if key not in a:
>>> raise BusinessError(...)
>>> return 1 / a[key] # possible TypeError, ZeroDivisionError, etc
>>
>> Yes, in that case the exception will appear unintentional and you get
>> the old message — it's on a best-effort basis.
>
> In both cases the BusinessError exception raised explicitly. How do you
> distinguish one case from another?
In my example code the "raise" keyword appears lexically inside the
"except" clause. The compiler would automatically emit a different
raise opcode in that case.
NB in your example the "raise" is just as intentional, but invoked from
a different function, which causes the above criterion to result in a
false negative. Even in so, the behavior would be no worse than now,
you'd just get the old message.
Hrvoje
More information about the Python-Dev
mailing list