001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.servlet; 018 019import javax.servlet.http.HttpServletRequest; 020import javax.servlet.http.HttpServletResponse; 021 022/** 023 * Interface to be implemented by objects that can resolve exceptions thrown during 024 * handler mapping or execution, in the typical case to error views. Implementors are 025 * typically registered as beans in the application context. 026 * 027 * <p>Error views are analogous to JSP error pages but can be used with any kind of 028 * exception including any checked exception, with potentially fine-grained mappings for 029 * specific handlers. 030 * 031 * @author Juergen Hoeller 032 * @since 22.11.2003 033 */ 034public interface HandlerExceptionResolver { 035 036 /** 037 * Try to resolve the given exception that got thrown during handler execution, 038 * returning a {@link ModelAndView} that represents a specific error page if appropriate. 039 * <p>The returned {@code ModelAndView} may be {@linkplain ModelAndView#isEmpty() empty} 040 * to indicate that the exception has been resolved successfully but that no view 041 * should be rendered, for instance by setting a status code. 042 * @param request current HTTP request 043 * @param response current HTTP response 044 * @param handler the executed handler, or {@code null} if none chosen at the 045 * time of the exception (for example, if multipart resolution failed) 046 * @param ex the exception that got thrown during handler execution 047 * @return a corresponding {@code ModelAndView} to forward to, 048 * or {@code null} for default processing in the resolution chain 049 */ 050 ModelAndView resolveException( 051 HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex); 052 053}