title: Exception message in Servlet
body: <p>I have JSON-RPC Service (a class with methods invoked using Reflection) and I want to pass exception as data to error object. So I try to catch Exception in Servlet but e.getMessage() return null, showing backtrace don't show my code at all (only function that get Stack trace and a place where I call it):</p>
  
  <pre><code>public Object loadService() throws InstantiationException, ClassNotFoundException, IllegalAccessException {
      ClassLoader parentClassLoader = ServiceReloader.class.getClassLoader();
      ServiceReloader classLoader = new ServiceReloader(parentClassLoader);
      //ClassLoader classLoader = init.class.getClassLoader();
      Class aClass = classLoader.loadClass("pl.jcubic.Service");
      return aClass.newInstance();
  }
  public String backTrace() {
      StackTraceElement[] stack = (new Throwable()).getStackTrace();
      String trace = "";
      for (int i=0; i&lt;stack.length; ++i) {
          trace += stack[i].toString() + "\n";
      }
      return trace;
  }
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      Object id = null;
      try {
          JSONRPC2Request reqIn = JSONRPC2Request.parse(this.getInputData(request));
          id = reqIn.getID();
  
          Object service = loadService();
  
          Method[] methods = service.getClass().getMethods();
  
          Object result = method.invoke(service, params);
          JSONRPC2Response respOut = new JSONRPC2Response(result, id);
          out.println(respOut);
  
      } catch (InvocationTargetException e) {
          out.println(internalError(id, e.getMessage(), backTrace()));
      }
  }
  </code></pre>
  
  <p>when a method throw Exception like <code>throw new Exception("Error occured");</code> (that message I want to send using JSON-RPC) I got this backtrace, </p>
  
  <pre><code>init.stackTrace(init.java:65)
  init.doPost(init.java:119)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
  org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
  org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
  org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
  org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
  org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
  org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
  org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
  org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  java.lang.Thread.run(Thread.java:724)
  </code></pre>
  
  <p>Is there any way to display my Exception I throw?</p>