title: How to throw exceptions in rest controllers
body: <p>I want to throw an exception from the controller. How can I do that?</p>
  
  <pre><code>@RequestMapping(value = "user", method = RequestMethod.POST, headers = "Accept=application/xml, application/json")
  public @ResponseBody
  AppUserDTO registerUser(@RequestBody AppUserDTO userDTO) {
  
  
          return userService.registerUser(userDTO);
  
  }
  </code></pre>
  
  <p>In this return it will throw an exception. Is there any kind of annotation I could use? How will the exception be passed to the client side as JSON?</p>