try: except <never>:
Tom Anderson
twic at urchin.earth.li
Tue Jan 10 18:35:00 EST 2006
On Tue, 10 Jan 2006, Duncan Booth wrote:
> 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():
>> ...
Nice.
> Or you can create an unraisable exception:
>
>>>> \
> class NeverRaised(Exception):
> def __init__(self, *args):
> raise RuntimeError('NeverRaised should never be raised')
Briliant! Although i'd be tempted to define an UnraisableExceptionError to
signal what's happened. Or ...
class ImpossibleException(Exception):
def __init__(self, *args):
raise ImpossibleException, args
Although crashing the interpreter is probably overkill.
tom
--
Like Kurosawa i make mad films; okay, i don't make films, but if i did
they'd have a samurai.
More information about the Python-list
mailing list