[Biojava-l] log4j

Thomas Down td2@sanger.ac.uk
Wed, 12 Jul 2000 13:55:58 +0100


On Wed, Jul 12, 2000 at 02:40:05PM +0100, hilmar.lapp@pharma.novartis.com wrote:
> 
>      Basically, I agree. From my experience, there's a problem with
>      triggering exceptions in the case of batch operations, like 'annotate
>      all seqs a database object returns'. You as a client don't want to
>      abort the called method at a particular sequence raising an exception
>      unless you can easily resume the operation, something which is often
>      not the case. What I did is to propagate such exceptions as events,
>      that is, create an ExceptionHandler interface, and methods carrying
>      out batch operations which are supposed not to fail on the first
>      exception now call an ExceptionHandler, and resume or abort based on
>      what the handler returns.

We've thought about this a bit before for BioJava.  If you do
go down the `batch operation' route, having some kind of
ExceptionHandler can make sense.  But the alternative way
to look at things is that batch operations and exceptions
just don't sit well together.  Sun seem to take this view,
and so do I.

The proper way to do a batch operation is something like:

  SequenceDB myDB = // ...
  for (SequenceIterator si = myDB.sequenceIterator(); 
       si.hasNext(); )
  {
    Sequence seq = si.nextSequence();
    try {
      // do something to seq
    } catch (Exception ex) {
      // Look at the exception, and either abort or continue
    }
  }

This `external iteration' pattern may be a few extra lines of code
compared to having a method which batch applies some operator
to every Sequence in a SequenceDB, but it DOES allow you to plug
in exactly the exception handling code you want, at the appropriate
level.  And it's the more common Java design pattern.

This kind of issue gets a brief mention on question 2 of the
Collections framework design FAQ.

Of course, there could be some cases where special exception
handlers are the best way to go.  But the external iteration
pattern works nicely in a great many cases, and I'd like to
stick to that wherever possible.

Thanks,
   Thomas.
-- 

He looked up with big brown eyes.  ``They're really only
tiny little A-bombs, honest.''
                                     -- David Brin.