title: Handle exceptions in a rest controller in Spring Boot
body: <p>I create REST web-service with Spring Boot. 
  I would like to know what is a better way to handle exceptions in a controller. I have seen other questions and didn’t found an answer. </p>
  
  <p>My controller:</p>
  
  <pre><code>@GetMapping
  public ResponseEntity&lt;?&gt; saveMyUser(){
      MyUser myUser = new MyUser(“Anna”);
  
      //throws SQLException
      MyUserDetails userDetails = userService.saveMyUser(myUser);
  
      //if successful
      return ResponseBody.ok(userDetails);
  }
  </code></pre>
  
  <p>saveMyUser() method of UserService:</p>
  
  <pre><code>public MyUserDetails saveUser(MyUser) throws SQLException {...}
  </code></pre>
  
  <p>So at this point I have at least 2 simple options:</p>
  
  <ol>
  <li><p>Add exception to method signature.
  Here I may rely on Spring Boot to pass all information about exception and status code to a client. However do not know if it is a reliable approach. </p></li>
  <li><p>Surround with try/catch and pass all information about exceptions manually.</p></li>
  </ol>
  
  <p>What is a better simple way? </p>