'Registers a handler for a given exception error type.
Error handlers may be registered for any type, including
:class:`~.HTTPError`. This feature provides a central location
for logging and otherwise handling exceptions raised by
responders, hooks, and middleware components.
A handler can raise an instance of :class:`~.HTTPError` or
:class:`~.HTTPStatus` to communicate information about the issue to
the client.  Alternatively, a handler may modify `resp`
directly.
Error handlers are matched in LIFO order. In other words, when
searching for an error handler to match a raised exception, and
more than one handler matches the exception type, the framework
will choose the one that was most recently registered.
Therefore, more general error handlers (e.g., for the
standard ``Exception`` type) should be added first, to avoid
masking more specific handlers for subclassed types.
Args:
exception (type): Whenever an error occurs when handling a request
that is an instance of this exception class, the associated
handler will be called.
handler (callable): A function or callable object taking the form
``func(ex, req, resp, params)``.
If not specified explicitly, the handler will default to
``exception.handle``, where ``exception`` is the error
type specified above, and ``handle`` is a static method
(i.e., decorated with @staticmethod) that accepts
the same params just described. For example::
class CustomException(CustomBaseException):
@staticmethod
def handle(ex, req, resp, params):
# TODO: Log the error
# Convert to an instance of falcon.HTTPError
raise falcon.HTTPError(falcon.HTTP_792)'

def add_error_handler(self, exception, handler=None):

    if (handler is None):
        try:
            handler = exception.handle
        except AttributeError:
            raise AttributeError('handler    must    either    be    specified    explicitly    or    defined    as    a    staticmethod    named    "handle"    that    is    a    member    of    the    given    exception    class.')
    self._error_handlers.insert(0, (exception, handler))
