title: Java6 RuntimeException that returns Http status code
body: <p>I found <a href="https://stackoverflow.com/questions/212239/what-java-exception-class-to-use-for-http-errors">another post</a> showing how we can create our own checked exceptions that also return a HTTP status code different from 500. However, I need it to be a <code>RuntimeException</code>. 
  Then, I found <a href="http://docs.oracle.com/javaee/6/api/javax/ws/rs/WebApplicationException.html" rel="nofollow noreferrer"><code>WebApplicationException</code></a> which is an unchecked exception, returns a HTTP status code but does not allow me to set message as in a regular exception.</p>
  
  <p>Is there any unchecked exception out there in Java EE 6 that allows me to set an error message like in a regular exception and also returns a HTTP status code that I can set?</p>
  
  <p><strong>Edit:</strong> Including an explanation of why I want this as requested by John.</p>
  
  <p>I created a filter to catch HTML and XSS attacks from my requests parameters. Instead of checking for that everytime in <code>Filter.doFilter</code> which would be too slow, I extended <code>HttpServletRequestWrapper</code> and used it like this.</p>
  
  <pre><code>HttpFilterRequest implements Filter
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
      try {
          chain.doFilter(new SafeHttpRequest((HttpServletRequest) request), response);
      } catch (SecurityViolationException e) {
          log.warn(format("A security violation was detected. Please enable debug for further details: %s]", e.getMessage()));
          HttpServletResponse resp = (HttpServletResponse) response;
          resp.sendError(e.getStatusCode());
      }response);
    }
  
  SafeHttpRequest extends HttpServletRequestWrapper (supressing parts to shorten code)
    @Override
    public String getParameter(String parameter) {
        return xssAndHtmlValidation(super.getParameter(parameter));
    }
    @Override
    public String getHeader(String name) {
        return xssAndHtmlValidation(super.getHeader(name));
    }
  </code></pre>
  
  <p><code>xssAndHtmlValidation()</code> throws <code>SecurityViolationException</code> which is a  <code>RuntimeException</code> but the <code>catch</code> block at <code>doFilter</code> doesn't work because my exception is thrown as a <code>ServletException</code> containing <code>SecurityViolationException</code>.</p>