In my own opinion, it is a very rare case that I will let the idiom "throws
Exception" appear in any code that I write.  It is almost always either a
bug or a bad design.

Letting apply throw Exception almost requires that forEachPair throws the
same excessively general exception.  That means that any code that uses this
iteration must either throw Exception or catch Exception and try to sort it
out with instanceof drecky code.  I can imagine it is OK for a framework to
internally include something horrid in the name of generality, but not if it
forces me to include that same goofiness in my own code.

So I would be strongly -1 on defining apply to throw Exception.  The code
you have here is a small pain the in the posterior to write, but it will
generally get written automagically by the IDE.  It has the great virtue of
meaning what it says.

One other option that I could imagine would be to let forEachPair be somehow
genericized to tell it what kind of exception that apply might throw.
Something like new Function<LegalException>() { bool apply(key,value) throws
LegalException {...} } might work.  Making this actually usable would
require lots of thought.

On Sat, Feb 13, 2010 at 1:20 PM, Robin Anil <robin.a...@gmail.com> wrote:

> forEachPair(function(){
>  @Override
>  bool apply(key, value){
>    try {
>         do something;
>         output.collect(key1,value1);
>    }
>    catch(IOException e){
>    throw new RuntimeException(e);
>    }
>    return true;
>  }
> }
>
> }
>
>
> What to do here? Why not let ObjectProcedure class throw Exception ?
>



-- 
Ted Dunning, CTO
DeepDyve

Reply via email to