Can one declare an abstract exception in Python?
Question: I would like to declare a hierarchy of user-defined exceptions in Python.
However, I would like my top-level user-defined class (`TransactionException`)
to be abstract. That is, I intend `TransactionException` to specify methods
that its subclasses are required to define. However, `TransactionException`
should never be instantiated or raised.

I have the following code:

    
    
    from abc import ABCMeta, abstractmethod
    
    class TransactionException(Exception):
        __metaclass__ = ABCMeta
    
        @abstractmethod
        def displayErrorMessage(self):
            pass
    

However, the above code allows me to instantiate `TransactionException`...

    
    
    a = TransactionException()
    

In this case `a` is meaningless, and should instead draw an exception. The
following code removes the fact that `TransactionException` is a subclass of
`Exception`...

    
    
    from abc import ABCMeta, abstractmethod
    
    class TransactionException():
        __metaclass__ = ABCMeta
    
        @abstractmethod
        def displayErrorMessage(self):
            pass
    

This code properly prohibits instantiation but now I cannot raise a subclass
of `TransactionException` because it's not an `Exception` any longer.

Can one define an abstract exception in Python? If so, how? If not, why not?

NOTE: I'm using Python 2.7, but will happily accept an answer for Python 2.x
or Python 3.x.


Answer: 
    class TransactionException(Exception):
    
        def __init__(self, *args, **kwargs):
            raise NotImplementedError('you should not be raising this')
    
    
    class EverythingLostException(TransactionException):
    
        def __init__(self, msg):
            super(TransactionException, self).__init__(msg)
    
    
    try:
        raise EverythingLostException('we are doomed!')
    except TransactionException:
        print 'check'
    
    try:
        raise TransactionException('we are doomed!')
    except TransactionException:
        print 'oops'
    

