Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4530846
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:50:42+00:00 2026-05-21T13:50:42+00:00

I have an implementation of a Spring AbstractHandlerExceptionResolver in my project. This handler takes

  • 0

I have an implementation of a Spring AbstractHandlerExceptionResolver in my project. This handler takes care of all exceptions thrown from controllers. For the most part, this works very well in handling our exceptional cases and translating them into Views/HTTP responses.

However, we have a requirement that something must be written to the response headers in every situation (even errors). This data must be configured/set in the controller actions themselves (as it is tied to whatever the controllers are doing). So, I’m trying to get this data through to my views so that it can be used.

Logically, it makes sense to put this data in the Model… However, it looks like the HandlerExceptionResolver interface does not persist anything the Controller has set in the Model (which would contain the data the controller must set).

Is there a way to access the Controller’s model values in a HandlerExceptionResolver implementation?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T13:50:43+00:00Added an answer on May 21, 2026 at 1:50 pm

    Let me first summarize:
    * you have an MVC controller method
    * if there is an exception in this controller method, then you want to take the model and do something different (then when there is no exception)

    For me it looks like normal exception handling:

    public ModelAndView myController() {
        Model model = new Model();
        model.put(...); 
        try {
           ...
           return new ModelAndView("success", model);
        } catch (SomethingWrongException e) {
           return new ModelAndView("failure", model);   
        }        
    }
    

    May you have noticed that the try block does not include the model population. – Because if it would be in the try block you should not use it in the catch clause, because may it is not populated.

    But this is what you try.
    What you try is a bit like this (from a conceptual point of view):

    try {
       ModelAndView modelAndView = invoke.myController()
    } catch (Exception e) {
       doSomethingWith(modelAndView);
    }
    

    So in general I belive you try some thing that is at lest not so advisable.
    (If it is a cross cutting concern, than it should not depend on the model)


    Anyway: lets find a way to get it working. Because a method can not return anything if it throws an exception, I assume that your controller method looks like this;

    public String myControllerMethod(ModelMap myModel) {
       myModel.put(...);
       if (Math.random()<0.5) {
         throws new RuntimeException("only a example");
       }
    }
    

    Because you what to use a HandlerExceptionResolver and not a concreate try/catch I guess you have a strange crosscuting concern that uses the Model. To implement it, I would use AOP. I would add an point cut and a arround advice for the controller methods, that return an other view name if an exception is thrown.

    public aspect ServletExceptionReporterAspect {
    
    pointcut stringRequestHandler() : 
        execution (@RequestMapping String com.demo..*(ModelMap));
    
    String around(ModelMap model): stringRequestHandler(){
        try {
            return proceed(model);
        } catch (Exception ex){
            System.out.println(model);
            return "myErrorView";
        }
    }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an implementation of default handler. When it gets to a   in
In our data access layer at work we have this standard implementation where the
I have a rather large spring application, and all I'm trying to share is
I have to migrate from Spring 2.5 to 3.0. My web services are still
We are using Spring Security 3. We have a custom implementation of PermissionEvaluator that
Does VbScript have a native implementation for Regex? I need to validate e-mail addresses
Does anyone have a good implementation of a stream cipher written in pure portable
I am learning about SOAP implementation and have become somewhat confused regarding the appropriate
Have created a c++ implementation of the Hough transform for detecting lines in images.
I have a priority queue implementation in C# that I want to add a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.