I have a REST web service controller that looks like this:
@RequestMapping(value = URIConstants.URL_DOCUMENT_SEARCH, method = RequestMethod.POST, produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) protected DocumentSearchResponse getDocuments(@Valid @ModelAttribute DocumentSearchRequest objDMSRequest,BindingResult bindingResult, HttpServletRequest objServletRequest) throws AppException { if (bindingResult.hasErrors()) { //I want to throw my custom exception here ///Or can anyone suggest a more clean and efficient way } -----More code and logic } I have a custom exception and handlers that will throw invalid HTTP invalid request exception. The custom exception has errorcode and error description fields. My requirement is is there a way to parse the error from the bindingresults to a custome exception and trow that in the controler.