title: Spring 3 - Create ExceptionHandler for NoSuchRequestHandlingMethodException
body: <p>Using Spring 3, I like to create an exception handler using the <strong>ExceptionHandler</strong> annotation that will handle <strong>"no page found (404)"</strong> requests.  I am using the following code to do this.  But when I point to a URL that does not exist, the default exception handler defined by Spring is being invoked.  </p>
  
  <p>It might be that I'm handling the <strong>NoSuchRequestHandlingMethodException</strong> exception.  If it is, then what exception should I be registering?</p>
  
  <p>Will you please take a look at the following code and see what I'm doing wrong?</p>
  
  <p>NOTE: If I change the exception in the <strong>@ExceptionHandler</strong> to <strong>NullPointerException</strong> and create a <strong>RequestMapping</strong> to throw null pointer, that will work.</p>
  
  <pre><code>    import org.springframework.stereotype.Controller;
      import org.springframework.web.bind.annotation.ExceptionHandler;
      import org.springframework.web.bind.annotation.RequestMapping;
  
      import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
  
      import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;
      import org.springframework.web.servlet.ModelAndView;
  
      @Controller
      public class GeneralHandler {
        private final Log logger = LogFactory.getLog(getClass());
  
        @ExceptionHandler(NoSuchRequestHandlingMethodException.class)
        public ModelAndView handleException (NoSuchRequestHandlingMethodException ex) {
          ModelAndView mav = new ModelAndView();
          logger.error("Exception found: " + ex);
          return mav;
        }
      }
  </code></pre>