title: HttpServletResponse.sendError(int sc) vs HttpServletResponse.setStatus(int sc)
body: <p>I use Spring mvc and my question is regarding the <code>sendError</code> method from <code>HttpServletResponse</code>.</p>
  
  <p>Can someone please tell me which is best between:</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST, produces = "application/json")
      public void createAdvertisement(@RequestBody @Validated(value = ValidationGroups.AdvertisementCreateUpdate.class) Advertisement advertisement, BindingResult bindingResult,
              HttpServletResponse response, @CurrentMember Member member) {
          if (bindingResult.hasErrors()) {
              response.setStatus(SC_BAD_REQUEST);
              return;
          }
          response.setStatus(SC_CREATED);
          advertisementService.createAdvertisement(member, advertisement);
      }
  </code></pre>
  
  <p>and that:</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST, produces = "application/json")
      public void createAdvertisement(@RequestBody @Validated(value = ValidationGroups.AdvertisementCreateUpdate.class) Advertisement advertisement, BindingResult bindingResult,
              HttpServletResponse response, @CurrentMember Member member) {
          if (bindingResult.hasErrors()) {
              response.sendError(SC_BAD_REQUEST);
          }
          response.setStatus(SC_CREATED);
          advertisementService.createAdvertisement(member, advertisement);
      }
  </code></pre>
  
  <p>Notice that in the first code snippet, I set the status code and return whereas in the second one I use the <code>sendError</code> method.</p>
  
  <p>Can someone please explain the pros and cons of both solutions?</p>