protected AjaxExceptionHandler findHandlerComponent(FacesContext context, Throwable rootCause) {
        AjaxExceptionHandlerVisitCallback visitCallback = new AjaxExceptionHandlerVisitCallback(rootCause);

        context.getViewRoot().visitTree(
                VisitContext.createVisitContext(context, null, ComponentUtils.VISIT_HINTS_SKIP_ITERATION.get()), visitCallback);

        Map<String, AjaxExceptionHandler> handlers = visitCallback.getHandlers();

        // get handler by exception type
        AjaxExceptionHandler handler = handlers.get(rootCause.getClass().getName());

        // lookup by inheritance hierarchy
        if (handler == null) {
            Class<?> throwableClass = rootCause.getClass();
            while (handler == null && throwableClass.getSuperclass() != Object.class) {
                throwableClass = throwableClass.getSuperclass();
                handler = handlers.get(throwableClass.getName());
            }
        }

        // get default handler
        if (handler == null) {
            handler = handlers.get(null);
        }

        return handler;
    }
Finds the proper {@link AjaxExceptionHandler} for the given {@link Throwable}.

@param context The {@link FacesContext}.
@param rootCause The occurred {@link Throwable}.
@return The {@link AjaxExceptionHandler} or <code>null</code>.
primefaces/src/main/java/org/primefaces/application/exceptionhandler/PrimeExceptionHandler.java