[Python-Dev] Explicitly declaring expected exceptions for a block

Dmitry Dvoinikov dmitry at targeted.org
Tue Jun 21 07:25:18 CEST 2005


Excuse me if I couldn't find that in the existing PEPs, but
wouldn't that be useful to have a construct that explicitly
tells that we know an exception of specific type could happen
within a block, like:

----------------------------------

ignore TypeError:
    do stuff
[else:
    do other stuff]

being essintially identical to

try:
    do stuff
except TypeError:
    pass
[else:
    do other stuff]
    
----------------------------------

The reason for that being self-tests with lots and lots of
little code snippets like this:

try:
    c().foo()
except TypeError:
    pass

which could be written as

ignore TypeError: c().foo()

Sincerely,
Dmitry Dvoinikov
http://www.targeted.org/



More information about the Python-Dev mailing list