On Tue, 10 Jan 2006, Duncan Booth wrote:

> Paul Rubin wrote:
>
>> Hallvard B Furuseth <[EMAIL PROTECTED]> 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.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to