title: Java `instanceof` and composition of a Throwable in onFailure
body: <p>In my GWT client I am trying to ensure that the <code>Throwable</code> passed to my <code>Callback#onFailure()</code> implementations is always handled, because many implementations in this vast code base doesn't do anything about it.</p>
  
  <p>To do this I have defined my own <code>RemoteServiceProxy#doCreateRequestCallback()</code> which wraps every <code>Callback</code> in my own implementation. In that <code>#onFailure()</code> method I want to use my own version of a <code>Throwable</code> so that I can track whether it gets handled, eg. when <code>Throwable#getMessage()</code> is called, so I pass it to the original <code>Callback#onFailure()</code>.</p>
  
  <pre class="lang-java prettyprint-override"><code>public class ThrowableProxy extends Throwable {
      private Throwable delegate;
      private boolean handled;
  
      public ThrowableProxy(Throwable delegate) {
          this.delegate = delegate;
          this.handled = false;
      }
  
      // Overriding Throwable's methods to defer to the delegate
  
      // package protected
      boolean isHandled() {
          return this.handled;
      }
  }
  </code></pre>
  
  <p>This all looks fine, until you hit <strong>instanceof</strong>. Now, if the client code wants to check the type of the exception, eg. <code>throwable instanceof StatusCodeException</code>, the Throwable is an instance of <code>ThrowableProxy</code>, but what I really want is to check the the type of the delegate.</p>
  
  <p>How does <strong>instanceof</strong> work? Can I somehow make it check the delegate without doing something like <code>throwable.getDelegate() instanceof StatusCodeException</code>?</p>