title: How to throw exception from an akka actor?
body: <p>I have a spring  boot application which I'm trying to integrate with akka. For most of the endpoints I'm relying on spring boot built in RuntimeException mechanism but akka actors does not allow to throw exception any thoughts?</p>
  
  <p>i have this helper for calling other services :</p>
  
  <pre><code>public ResponseEntity&lt;R&gt; callService(String address
          , MultiValueMap&lt;String, String&gt; headers
          , B body
          , HttpMethod httpMethod
          , ParameterizedTypeReference&lt;R&gt; parameterizedTypeReference
          , ExceptionHandlerCustom exceptionHandlerCustom) {
      try {
          HttpEntity&lt;B&gt; request = new HttpEntity&lt;&gt;(body, headers);
          return restTemplate.exchange(address
                  , httpMethod
                  , request
                  , parameterizedTypeReference);
      } catch (Exception e) {
          if (e instanceof HttpStatusCodeException) {
              HttpStatusCodeException exception = (HttpStatusCodeException) e;
              Gson gson = new Gson();
              Response&lt;String&gt; errorResponse =
                      gson.fromJson(exception.getResponseBodyAsString(), new TypeToken&lt;Response&lt;String&gt;&gt;(){}.getType());
              if (exception.getStatusCode().equals(HttpStatus.BAD_REQUEST)) {
                  throw new BadRequestException(errorResponse.getMessage());
              } else if (exception.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
                  throw new UnauthorizedException("not authorized");
              } else if (exception.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)) {
                  e.printStackTrace();
                  throw new InternalServerErrorException();
              } else if (exceptionHandlerCustom != null) {
                  exceptionHandlerCustom.handle(e);
              }else
                  e.printStackTrace();
          }
          throw e;
      }
  }
  </code></pre>
  
  <p>I have an actor that calls this method and I want to re-throw the exception right when it happens (I know that the life-cycle of an actor cannot be broken)  </p>
  
  <p>my exceptions are all like this:</p>
  
  <pre><code>@ResponseStatus(HttpStatus.NOT_FOUND)
  public class NotFoundException extends RuntimeException {
      public NotFoundException(String message) {
          super(message);
      }
  }
  </code></pre>
  
  <p>and in my actor I have this method:</p>
  
  <pre><code>@Override
      public Receive createReceive() {
      return receiveBuilder()
              .match(CheckUserIdAndProvidedToken.class, message -&gt; {
                  getSender().tell(tokenCheckService.checkUserIdAndProvidedToken(message.getToken()
                          , message.getId()), getSelf());
              })
              .build();
  }
  </code></pre>
  
  <p>and in the service I call it like this:</p>
  
  <pre><code>Future&lt;Object&gt; futureOfCheck = ask(checker, new         
  TokenCheckActor.CheckUserIdAndProvidedToken(id, token), timeout);
  </code></pre>
  
  <p>and when exception occurs I like to throw this to clients (spring boot exception in json format):</p>
  
  <pre><code>{
      "timestamp": "2019-02-06T06:42:26.740+0000",
      "status": 404,
      "error": "Not Found",
      "message": "user not found",
      "path": "/xxxx/yyy/ssss"
  }
  </code></pre>