':type key: None|str
:type code_or_exception: int|T<=Exception
:type f: callable'

@setupmethod
def _register_error_handler(self, key, code_or_exception, f):

    if isinstance(code_or_exception, HTTPException):
        raise ValueError('Tried    to    register    a    handler    for    an    exception    instance    {0!r}.    Handlers    can    only    be    registered    for    exception    classes    or    HTTP    error    codes.'.format(code_or_exception))
    try:
        (exc_class, code) = self._get_exc_class_and_code(code_or_exception)
    except KeyError:
        raise KeyError("'{0}'    is    not    a    recognized    HTTP    error    code.    Use    a    subclass    of    HTTPException    with    that    code    instead.".format(code_or_exception))
    handlers = self.error_handler_spec.setdefault(key, {}).setdefault(code, {})
    handlers[exc_class] = f
