More flexible exception handling.

Add base class for our exceptions and let several subclasses extend it.