def METHOD_NAME(self, exception, route_name: Optional[str] = None):
    """Lookup the existing instance of `ErrorHandler` and fetch the registered handler for a specific type of exception.
    This method leverages a dict lookup to speedup the retrieval process.
    Args:
        exception (sanic.exceptions.SanicException or Exception): Type
            of exception.
    Returns:
        Registered function if found, ``None`` otherwise.
    """  # noqa: E501
    exception_class = type(exception)
    for name in (route_name, None):
        exception_key = (exception_class, name)
        handler = self.cached_handlers.get(exception_key)
        if handler:
            return handler
    for name in (route_name, None):
        for ancestor in type.mro(exception_class):
            exception_key = (ancestor, name)
            if exception_key in self.cached_handlers:
                handler = self.cached_handlers[exception_key]
                self.cached_handlers[
                    (exception_class, route_name)
                ] = handler
                return handler
            if ancestor is BaseException:
                break
    self.cached_handlers[(exception_class, route_name)] = None
    handler = None
    return handler