Close
« Tutorial

Spring MVC - HandlerExceptionResolverComposite MCQ

0/13
0 ✓
0 ✗

1. What is the main purpose of HandlerExceptionResolverComposite?

2. Which method is used to provide a list of resolvers to a composite resolver?

HandlerExceptionResolverComposite c =
    new HandlerExceptionResolverComposite();
c.____(List.of(r1, r2));

3. A composite has several resolvers in its list. How does Spring select the result from them?

4. What is the output of this code?

HandlerExceptionResolver a = (rq, rs, h, ex) -> null;
HandlerExceptionResolver b = (rq, rs, h, ex) -> null;
HandlerExceptionResolverComposite c =
    new HandlerExceptionResolverComposite();
c.setExceptionResolvers(List.of(a, b));
ModelAndView mv =
    c.resolveException(req, res, null, new Exception());
System.out.println(mv);

5. A resolver in the composite's list implements Ordered. Does its getOrder() value change the order in which the composite tries the resolvers?

6. A controller throws an IllegalStateException. What view name is selected?

HandlerExceptionResolver custom = (rq, rs, h, ex) -> null;
SimpleMappingExceptionResolver s =
    new SimpleMappingExceptionResolver();
s.setDefaultErrorView("fallback");
Properties p = new Properties();
p.setProperty(IllegalAccessException.class.getName(), "denied");
s.setExceptionMappings(p);
HandlerExceptionResolverComposite c =
    new HandlerExceptionResolverComposite();
c.setExceptionResolvers(List.of(custom, s));
ModelAndView mv =
    c.resolveException(null, null, null, new IllegalStateException());
System.out.println(mv.getViewName());

7. Which interface does HandlerExceptionResolverComposite implement, so that it can be used like any other exception resolver?

8. What does this code do?

@Override
public void extendHandlerExceptionResolvers(
        List<HandlerExceptionResolver> resolvers) {
         ...... 
        resolvers.add(composite);
}
Join