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 7752065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:42:21+00:00 2026-06-01T11:42:21+00:00

I have @Controller @RequestMapping(value=core/*) public class CoreController { public static String exceptionOccurredView = /core/exceptionOccurred;

  • 0

I have

@Controller
@RequestMapping(value="core/*")
public class CoreController {

    public static String exceptionOccurredView = "/core/exceptionOccurred";

    @ExceptionHandler(Throwable.class)
    public ModelAndView exceptionOccurred(Throwable exception, HttpServletResponse response, HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        mv.setViewName ( exceptionOccurredView );
        mv.addObject   ( "requestedUrl", Core.getCurrentUrlWithParams() );
        mv.addObject   ( "exception", exception );

        System.out.println( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + Core.getCurrentUrlWithParams() );
        return mv;
    }   

    @RequestMapping
    public void test0(HttpServletResponse response, HttpServletRequest request) throws IOException {
        throw new IOException();
    } 

}

which works fine for all exeptions occuring under core url.

if I go to url

localhost:8080/core/test0

the error page is shown. Also if I go to:

localhost:8080/core/actionDoesNotExist

but if I use:

localhost:8080/controllerDoesNotExist/test0

The error does not get shown, since the annotation @ExceptionHandler is valid only per controller.

So how can you achieve a global, non-controller attached exception/error handler ?

  • 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-06-01T11:42:23+00:00Added an answer on June 1, 2026 at 11:42 am

    One way would be to use some implementation of HandlerExceptionResolver.

    For example to use `SimpleMappingExceptionResolver, put this in your context:

    <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <property name="exceptionMappings">
          <map>
             <entry key="IOException" value="io-error" />
          </map>
        </property>
        <property name="defaultErrorView" value="default-error"/>
    </bean>
    

    That way you define a global mapping from exceptions to error pages. If you need some more complicated error handling, implement your own resolver.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Controller : @Controller @RequestMapping(/path/*) public class MyController { @RequestMapping(value = /,
I have written the following code : @Controller @RequestMapping(/test) public class Home { @RequestMapping(value
I have a simple Controller that looks like this:- @Controller @RequestMapping(value = /groups) public
I have @RequestMapping(value = /UpdatePassword, method = RequestMethod.GET) public String myUpdate() That I want
I have a simple controller specified below, @Controller @RequestMapping(/add/*) public class RequestMappingController { @Autowired
I have a Spring MVC Controller class (bean): @Controller @RequestMapping(/index.jsp) public class EjbCaller {
I have a controller with an action method as follows: public class InventoryController :
Currently I have the following Mapping in my Controller: @RequestMapping( value = /add.html, method
I have the following Spring Controller @Controller @RequestMapping(/accreq) with the following mapping @RequestMapping(value =
When I try to do like below and I have a RequestMapping controller class

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.