try: except <never>:
Duncan Booth
duncan.booth at invalid.invalid
Tue Jan 10 09:24:35 EST 2006
Paul Rubin wrote:
> Hallvard B Furuseth <h.b.furuseth at usit.uio.no> writes:
>> > class NeverRaised(Exception): pass
>> > for ex in ZeroDivisionError, NeverRaised:
>>
>> Heh. Simple enough. Unless some obstinate person raises it anyway...
>
> Hmm, ok, how's this?:
>
> def NeverRaised():
> class blorp(Exception): pass
> return blorp
> for ex in ZeroDivisionError, NeverRaised():
> ...
Or you can create an unraisable exception:
>>> \
class NeverRaised(Exception):
def __init__(self, *args):
raise RuntimeError('NeverRaised should never be raised')
>>> \
try:
raise NeverRaised
except NeverRaised:
print "caught it"
Traceback (most recent call last):
File "<pyshell#47>", line 4, in __init__
raise RuntimeError('NeverRaised should never be raised')
RuntimeError: NeverRaised should never be raised
More information about the Python-list
mailing list