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
022import org.springframework.lang.Nullable;
023
024/**
025 * Interface to be implemented by objects that can resolve exceptions thrown during
026 * handler mapping or execution, in the typical case to error views. Implementors are
027 * typically registered as beans in the application context.
028 *
029 * <p>Error views are analogous to JSP error pages but can be used with any kind of
030 * exception including any checked exception, with potentially fine-grained mappings for
031 * specific handlers.
032 *
033 * @author Juergen Hoeller
034 * @since 22.11.2003
035 */
036public interface HandlerExceptionResolver {
037
038        /**
039         * Try to resolve the given exception that got thrown during handler execution,
040         * returning a {@link ModelAndView} that represents a specific error page if appropriate.
041         * <p>The returned {@code ModelAndView} may be {@linkplain ModelAndView#isEmpty() empty}
042         * to indicate that the exception has been resolved successfully but that no view
043         * should be rendered, for instance by setting a status code.
044         * @param request current HTTP request
045         * @param response current HTTP response
046         * @param handler the executed handler, or {@code null} if none chosen at the
047         * time of the exception (for example, if multipart resolution failed)
048         * @param ex the exception that got thrown during handler execution
049         * @return a corresponding {@code ModelAndView} to forward to,
050         * or {@code null} for default processing in the resolution chain
051         */
052        @Nullable
053        ModelAndView resolveException(
054                        HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex);
055
056}