Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Jetty behaviour when a java.lang.error is thrown

Situation came up where one of our handlers was throwing a java.lang.error and I am wondering what the expected jetty behaviour is.

2 things I observed:

1. A response is never sent to the client when an Error is thrown.
2. Request logging is incorrect when an error is thrown.

With the following setup:

public class JettyErrorThrowing {
  public static class ThrowingHandler extends ContextHandler {
    public ThrowingHandler() {

    public void doHandle(String arg0, Request arg1, HttpServletRequest arg2,
        HttpServletResponse arg3) throws IOException, ServletException {
      throw new Error("ThrowingHandler thrown error");

  public static void main(String[] args) throws Exception {
    Server server = new Server(8080);

    RequestLogHandler requestLogHandler = new RequestLogHandler();
    requestLogHandler.setRequestLog(new NCSARequestLog("JettyErrorThrowing.log"));
    requestLogHandler.setHandler(new ThrowingHandler());



A request to /throwerror/ will result in the following printed to the request log:
0:0:0:0:0:0:0:1 -  -  [19/Aug/2014:11:01:57 +0000] "GET /throwerror/ HTTP/1.1" 200 - "-" "snipped ua"

This is obviously incorrect as the response status is logged as 200 but a response is never sent.

What is the expected behaviour on a thrown error?
Would you like me to file the request log behaviour as a bug?


Back to the top