[Python-Dev] PEP 409 and the stdlib

Serhiy Storchaka storchaka at gmail.com
Tue May 21 11:56:14 CEST 2013


21.05.13 12:28, Hrvoje Niksic написав(ла):
> On 05/21/2013 10:36 AM, Serhiy Storchaka wrote:
>>>      The above exception was converted to the following exception:
>>>      ...
>>>
>>> That makes it clear that the conversion was explicit and (hopefully)
>>> intentional, and that the latter exception supersedes the former.
>>
>> How do you distinguish intentional and unintentional exceptions?
>
> By the use of the "raise" keyword.  Given the code:
>
> try:
>      x = d['key']
> except KeyError:
>      raise BusinessError(...)
>
> ....the explicit raising is a giveaway that the new exception was quite
> intentional.

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




More information about the Python-Dev mailing list