code: @SuppressWarnings("unchecked")
      protected void handleException(@Nonnull Throwable rex,
                                     @Nonnull Serializer responseSerializer,
                                     @Nonnull HttpServletRequest httpRequest,
                                     @Nonnull HttpServletResponse httpResponse) throws IOException {
          if (rex instanceof PMessage) {
              PMessage mex = (PMessage) rex;
              httpResponse.setStatus(statusCodeForException(rex));
              httpResponse.setContentType(responseSerializer.mediaType());
              responseSerializer.serialize(httpResponse.getOutputStream(), mex);
          } else {
              httpResponse.sendError(statusCodeForException(rex), rex.getMessage());
          }
      }
docs: Handle exceptions from the handle method.
  
  @param rex The response exception, which is the thrown exception or one
  of it's causes. See {@link #getResponseException(Throwable)}.
  @param responseSerializer The serializer to use to serialize message output.
  @param httpRequest The HTTP request.
  @param httpResponse The HTTP response.
  @throws IOException If writing the response failed.