title: Global Exception Handling in Jersey
body: <p>Is there a way to have global exception handling in Jersey?  Instead of individual resources having try/catch blocks and then calling some method that then sanitizes all of the exceptions to be sent back to the client, I was hoping there was a way to put this where the resources are actually called.  Is this even possible?  If so, how?</p>
  
  <p>Instead of, where <code>sanitize(e)</code> would throw some sort of Jersey-configured exception to the Jersey servlet:</p>
  
  <pre><code>@GET
  public Object getStuff() {
      try {
          doStuff();
      } catch (Exception e) {
          ExceptionHandler.sanitize(e);
      }
  }
  </code></pre>
  
  <p>Having:</p>
  
  <pre><code>@GET
  public Object getStuff() throws Exception {
      doStuff();
  }
  </code></pre>
  
  <p>where the exception would get thrown to something that I can intercept and call <code>sanitize(e)</code> from there.</p>
  
  <p>This is really just to simplify all the Jersey resources and to guarantee that the exceptions going back to the client are always in some sort of understandable form.</p>