title: StatusCodeException Vs. RuntimeException in GWT
body: <p>In my GWT app. I overrode RemoteServiceServlet to check if the session is valid right before the service method is being called. I am trying to throw a RuntimeException("expired session") from the server and I would like the client to catch this exception from the asynccallback onFailure...</p>
  
  <p>In the client I would like to:
  Asynccallback:</p>
  
  <pre><code>@Override
      public void onFailure(Throwable caught) {
          final String message = caught.getMessage();
  
          if (!isNullOrEmptyString(message) &amp;&amp; message.contains("expired session")) {
              com.google.gwt.user.client.Window.Location.reload();
          }
  
      }
  </code></pre>
  
  <p>However, in the client, the caught object is still a StatusCodeException and the message is still the default "...Exception in the server...". how can I override the exception at least the default message to compare if it was a session expired message I sent from the server?</p>
  
  <p>thanks</p>
  
  <p>Hi Gursel,
  Here's my code:
  -> Custom RemoteServiceServlet. I'm trying to "intercept" every method before it's invoked. I check the session and throw a RuntimeException if it's already expired. So basically, it is not the declared method that throws the exception but the custom RemoteServiceServlet. It still goes to the "onFailure" in the client async but the Throwable object is still of type "StatusCodeException" without the EXPIRED_SESSION_MSG message. Don;t know how to make this work. Thanks!</p>
  
  <pre><code>public class XRemoteServiceServlet extends RemoteServiceServlet {
      private final static String EXPIRED_SESSION_MSG = "ERROR: Application has expired session.";   
      @Override
      protected void onAfterRequestDeserialized(RPCRequest rpcRequest) {
          HttpServletRequest httpServletRequest = this.getThreadLocalRequest();
          HttpSession session = httpServletRequest.getSession(false);
          if (session != null) {
              final String sessionIdFromRequestHeader = getSessionIdFromHeader();
              if (!isNullOrEmptyString(sessionIdFromRequestHeader)) {
                  final String sessionId = session.getId();
  
                  if (!sessionId.equals(sessionIdFromRequestHeader)) {
                      throw new RuntimeException(EXPIRED_SESSION_MSG);
                  }
              }
  </code></pre>