Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@ExceptionHandler not being invoked

After some time researching and trying different things I still cannot get my @ExceptionHandler to be invoked in my jUnit integration test. Please, help me understand why?

@RequestMapping(value = "/someURL", method = RequestMethod.POST)
public ModelAndView batchUpload(@RequestBody final String xml, @RequestParam boolean replaceAll)
    throws IOException, URISyntaxException, SAXException, ParserConfigurationException, InvocationTargetException, IllegalAccessException, UnmarshallingFailureException
{
StreamSource source = new StreamSource(new StringReader(xml));
DomainClass xmlDomainClass;

try
{
    xmlDomainClass = (DomainClass) castorMarshaller.unmarshal(source);
}
catch (UnmarshallingFailureException me)
{
    // some logging. this gets executed
    throw me;
}

.

@ExceptionHandler(Throwable.class)
public ModelAndView handleUnmarshallingExceptions(Throwable th)
{
// never executes anything in here
return new ModelAndView( /*some parameters */ );
}

1 Answers

Spring: RESTful controllers and error handling helped me, my problem was the lack of this:

@Component
public class AnnotatedExceptionResolver extends AnnotationMethodHandlerExceptionResolver{
  public AnnotatedExceptionResolver() {
    setOrder(HIGHEST_PRECEDENCE);
  }
}
like image 161
Erik Avatar answered Mar 07 '26 14:03

Erik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!