title: JAX-RS exception mapper: What about wrapped exceptions and default case?
body: <p>A typical way to deal with exceptions in REST service is to define custom exception types (typically from <code>RuntimeException</code>) and then implement a mapper class to produce HTTP codes, for example:</p>
  
  <pre><code>public class MyExceptionMapper implements ExceptionMapper&lt;MyException&gt; {
    @Override
    public Response toResponse(MyExceptionex) {
      return Response.status(400).entity("bad request")
        .type(MediaType.APPLICATION_JSON).build();
    }
  }
  </code></pre>
  
  <p>Now, I have 2 questions:</p>
  
  <ul>
  <li>How would I implement a mapper for the "default case", meaning for every exception not mapped here or in another mapper? When for example implementing one for <code>Throwable</code> in order to produce an HTTP 500, wouldn't it catch my own exceptions again? Or can an order be defined in which mappers work?</li>
  <li>When calling managed components like EJBs from REST service, wouldn't an exception thrown there result in an <code>EJBException</code> or some <code>Transaction...Exception</code> wrapping my own one?</li>
  </ul>