In my GWT client I am trying to ensure that the Throwable
passed to my Callback#onFailure()
implementations is always handled, because many implementations in this vast code base doesn't do anything about it.
To do this I have defined my own RemoteServiceProxy#doCreateRequestCallback()
which wraps every Callback
in my own implementation. In that #onFailure()
method I want to use my own version of a Throwable
so that I can track whether it gets handled, eg. when Throwable#getMessage()
is called, so I pass it to the original Callback#onFailure()
.
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;
}
}
This all looks fine, until you hit instanceof. Now, if the client code wants to check the type of the exception, eg. throwable instanceof StatusCodeException
, the Throwable is an instance of ThrowableProxy
, but what I really want is to check the the type of the delegate.
How does instanceof work? Can I somehow make it check the delegate without doing something like throwable.getDelegate() instanceof StatusCodeException
?