title: How to return exception message to calling api in Java?
body: <p>I have an already implemented controller method which returns a value or throws an exception.</p>
  
  <pre><code>@Override
      @PostMapping(Endpoint.SUB_RESOURCE)
      @ResponseStatus(HttpStatus.CREATED)
      public EmployeeBankAccountOutputDto createBankAccount(@ApiParam("Account data") @RequestBody final EmployeeBankAccountInputDto accountCreationDto) {
  
          try {
              return service.createBankAccount(accountCreationDto);
          } catch (InvalidAccountDataException ex) {
              throw new InvalidAccountDataResponseException(ex, ex.getErrors());} 
          } catch (CountryNotFoundException ex) {
              throw new CountryNotFoundResponseException(ex.getCountryCode(), ex);
          }
      }
  </code></pre>
  
  <p>In this code I want to just log exception message in warning level and not throwing exception because I don't want to see something like :</p>
  
  <pre><code>14:37:02,610 ERROR [] c.m.w.ApiExceptionHandler:135 -  Account API error occurred: 400
  </code></pre>
  
  <p>So if I just put </p>
  
  <p><code>log.warn(ex.getMessage());</code> to the first catch statement, it is giving </p>
  
  <blockquote>
    <p>missing return statement</p>
  </blockquote>
  
  <p>error for that catch block as normal. So How can handle not throwing exception to calling api and just send the exception message properly, because return type of the method is a dto?</p>