commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henri Yandell <bay...@generationjava.com>
Subject Re: [Lang] Generic interface for handling exceptions
Date Wed, 31 Jul 2002 08:41:10 GMT

Have been pondering this for a few hours now. Trying to weigh up pro's
and con's. My immediate thoughts are that it doesn't really add any
functionality to Lang, just a standardised interface. There's no way we
could add many implementations beyond a System.err/out based one.

As far as users are concerned, I would normally expect to use Log4J or
something in this kind of area. It's only when I can't choose a logging
API dependency that it would have use. Except there is already a solution
in this case [though I've not used it before] ie) commons-logging. Though
I admit it is possible that when I handle the Throwable I might want to do
something other than just log it or mail a log etc. Maybe it's a feature
which could be added to commons-logging?

Three other ideas are bouncing in my head at the moment. The first is the
fact it is Thread based and there is always Commons-threading. But
something like this would just get lost there.

The second is that it is framework based and might be something that would
be good to discuss with the Avalon people. Framework's being their
speciality.

The last is that it is a pattern. The 'what to do when you want/have to
ignore an Exception' pattern (?). So maybe it's something that would fit
the more framework-like Commons-pattern project.

Or maybe it's just nearly 5am and sleep and I should really be happening.

The bottom line being, standardised interfaces in Commons Lang make me
uncomfortable. There are so many we can add, and I feel the strength of
Lang is in immediate usage of code in any Java project.

Hen

On Tue, 30 Jul 2002, Jack, Paul wrote:

> Hi,
>
> 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 {
>               doSomething();
>           } catch (Exception e) {
>               this.handler.handleThrowable(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 {
>                  listeners[i].someEventOccurred(event);
>              } catch (RuntimeException e) {
>                  handler.handleThrowable(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.
>
> -Paul
>
>
> --
> To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message