Close
« Tutorial

Spring MVC - HandlerExceptionResolver MCQ

0/13
0 ✓
0 ✗

1. What kind of problem does HandlerExceptionResolver deal with?

2. How is HandlerExceptionResolver different from error handling configured in web.xml?

3. How does a HandlerExceptionResolver tell Spring MVC to show a specific error page?

4. The handler parameter of resolveException() normally holds which type?

5. Which method name should be used to register a custom resolver in the configuration class?

@Configuration
@EnableWebMvc
public class AppConfig  implements WebMvcConfigurer {

    @Override
    public void ____(List<HandlerExceptionResolver> resolvers) {
        resolvers.add(new MyResolver());
    }
}

6. A JSP view resolver maps view names to /WEB-INF/pages/ with the .jsp suffix. A user opens /pay. What does the browser show?

@Override
public void configureHandlerExceptionResolvers(
        List<HandlerExceptionResolver> resolvers) {
    resolvers.add((req, res, handler, ex) ->
        new ModelAndView("oops")
            .addObject("msg", ex.getMessage())
    );
}
@GetMapping("/pay")
public void pay() {
    throw new IllegalStateException("No funds");
}
<!-- /WEB-INF/pages/oops.jsp -->
<p>Error: ${msg}</p>

7. A custom resolver is registered. The interceptor method below throws an exception. What happens?

public boolean preHandle(
        HttpServletRequest req,
        HttpServletResponse res,
        Object handler) throws Exception {
    throw new Exception("blocked");
}

8. Since Spring 6.1, what happens by default when a request URL has no matching handler?

9. By default in Spring versions before 6.1, is resolveException() called for an unmapped URL that gives a 404 error?

Join