try: except <never>:

Duncan Booth duncan.booth at invalid.invalid
Wed Jan 11 09:19:39 EST 2006


Tom Anderson wrote:

>> 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.

Crashng the interpreter would be, but what you just wrote is simply a more 
obscure way of raising RuntimeError :-)

>>> class ImpossibleException(Exception):
...     def __init__(self, *args):
...             raise ImpossibleException, args
...
>>> raise ImpossibleException
Traceback (most recent call last):
  File "<stdin>", line 3, in __init__
RuntimeError: maximum recursion depth exceeded



More information about the Python-list mailing list