I am using GWTP and RequestFactory on my client.
I would like any Fatal Exception to be handled by a custom UncaughtExceptionHandler. I have created my custom handler and registered it in the configure() call of my entry point module:
public class ClientModule extends AbstractPresenterModule {
@Override
protected void configure() {
// Register Uncaught Exception Handler first thing
GWT.setUncaughtExceptionHandler( new CustomUncaughtExceptionHandler() );
...
However, if on my client I throw an Exception
throw new RuntimeException("test");
The exception is not captured. In dev mode, I see the uncaught exception go all the way to the development console. Further debugging shows that GWT has not registered my custom handler:
handler = GWT.getUncaughtExceptionHandler();
returns
com.google.gwt.core.client.GWT$DefaultUncaughtExceptionHandler@370563b1
Any ideas on why GWT.setUncaughtExceptionHandler is not working?
For the record, I followed this post by cleancodematters. The only difference between his implementation and mine is that I use GWTP (and GIN) on the client.
I think you can't use GIN's ClientModule
to set your UncaughtExceptionHandler
.
Instead create a custom PreBootstrapper:
A PreBootstrapper allows you to hook into the GWTP bootstrapping process right before it starts. This is particularly useful if you need something done before GWTP starts up. In general the use of a Bootstrapper is advised but there are cases where that is not enough,for example when setting up an UncaughtExceptionHandler for gwt-log.
<set-configuration-property name="gwtp.prebootstrapper"
value="com.arcbees.project.client.PreBootstrapperImpl"/>
public class PreBootstrapperImpl implements PreBootstrapper {
@Override
public void onPreBootstrap() {
GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void onUncaughtException(final Throwable e) {
Window.alert("There was a problem loading your application");
}
});
}
}