Java Chatter and Random Nagging

Sunday, September 23, 2007

Handle Runtime Exceptions In Echo2

I was looking for a transparant mechanism to handle runtime exceptions in Echo2. Apparently Echo2 does not provide any hook for gracefully handling runtime exceptions due to the following posts. Since one solution lost access to the current Application Instance and the other involved changing Echo2 source code, I have found my own solution to this problem:

public class ExceptionalUpdateManager extends UpdateManager{
private static final long serialVersionUID = 1L;

public ExceptionalUpdateManager(ApplicationInstance applicationInstance) {
super(applicationInstance);
}

public void processClientUpdates()
{
try{
super.processClientUpdates();
}catch(AbstractHrutilRuntimeException exception){
//Hook : I show an error popup with the translation of the error code.
TopContentPane.getTopContentPane().add(new ErrorPane(exception.getErrorCode()));
}
}

}

and I overwrite (little bit of hacking with reflection) the UpdateManager of the ApplicationInstance as follows:

public ApplicationInstanceChild() {
super();
ReflectionUtil.setField(this, "updateManager", new ExceptionalUpdateManager(this));
}

This should solve the problem ! Every time a runtime exception is propagated, an error popup is shown with a description of the problem.

Labels: ,

3 Comments:

At 8:09 am, Anonymous Anonymous said...

I like the Idea, however it is a bit hacky and probably might aswell cause some exceptions.

What ReflectionUtil class are you using?

 
At 3:49 pm, Blogger SoftWarre said...

I agree that it is a bit hacky. But it was the fastest workaround I could come up with.

ReflectionUtil is a simple convenience class I have written myself.

 
At 3:10 pm, Blogger Alexandre said...

This comment has been removed by the author.

 

Post a Comment

<< Home