001/* 002 * Copyright 2002-2012 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.ServletException; 020 021import org.springframework.util.Assert; 022 023/** 024 * Exception to be thrown on error conditions that should forward 025 * to a specific view with a specific model. 026 * 027 * <p>Can be thrown at any time during handler processing. 028 * This includes any template methods of pre-built controllers. 029 * For example, a form controller might abort to a specific error page 030 * if certain parameters do not allow to proceed with the normal workflow. 031 * 032 * @author Juergen Hoeller 033 * @since 22.11.2003 034 */ 035@SuppressWarnings("serial") 036public class ModelAndViewDefiningException extends ServletException { 037 038 private ModelAndView modelAndView; 039 040 041 /** 042 * Create new ModelAndViewDefiningException with the given ModelAndView, 043 * typically representing a specific error page. 044 * @param modelAndView ModelAndView with view to forward to and model to expose 045 */ 046 public ModelAndViewDefiningException(ModelAndView modelAndView) { 047 Assert.notNull(modelAndView, "ModelAndView must not be null in ModelAndViewDefiningException"); 048 this.modelAndView = modelAndView; 049 } 050 051 /** 052 * Return the ModelAndView that this exception contains for forwarding to. 053 */ 054 public ModelAndView getModelAndView() { 055 return modelAndView; 056 } 057 058}