commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jack, Paul" <>
Subject [Lang] Generic interface for handling exceptions
Date Tue, 30 Jul 2002 20:52:31 GMT

I'd like to propose a simple interface for Lang for 
asynchronous exception handling:

    public interface ThrowableHandler {
        void handleThrowable(Throwable t)

It would have a variety of uses across many commons
projects.  Basically you'd use it whenever you would
otherwise silently ignore an exception.

It'd be handy more or less every time you
write your own thread, since the run() method can't
raise checked exceptions:

  public class MyThread extends Thread {

      public MyThread(ThrowableHandler handler) {
          this.handler = handler;

      public void run() {
          try {
          } catch (Exception e) {


It would also be useful for implementing an interface
whose methods don't allow you to raise checked exceptions;
a user could pass a ThrowableHandler to your implementation
to log exceptions, say.

Or if you're using the JavaBeans event pattern, and you 
don't want one buggy listener's RuntimeExceptions to 
interfere with the other listeners:

     void fireSomeEvent(SomeEvent event) {
         for (int i = 0; i < listeners.length; i++) {
             try {
             } catch (RuntimeException e) {

To take a concrete example, in pool.GenericObjectPool, there's
many cases where the methods declared by PoolableObjectFactory 
raise exceptions, but the pool implementation simply catches
and ignores them.  By passing a ThrowableHandler to GenericObjectPool, 
those exceptions could be logged or otherwise remembered.


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message