[concurrency-interest] Exception handling with ParallelArray

Neal Gafter neal at gafter.com
Fri Dec 28 10:05:43 EST 2007


On Dec 28, 2007 6:45 AM, Neal Gafter <neal at gafter.com> wrote:

> On Dec 28, 2007 5:57 AM, Doug Lea <dl at cs.oswego.edu> wrote:
>
> > Neal Gafter wrote:
> > > I don't get it.  (2), above, seems like a reason to include fancier
> > > support for exception tunneling (the generic exception type can be
> > > placed in the throws clause of ParallelArray.apply), rather than a
> > > reason not to.
> >
> > Maybe so. I don't think I've seen a proposal that boils down
> > to this sort of selective tunneling without adding more declaration
> > overhead in those cases it isn't used though.
>
>
> Again, I don't get it.  This comment sounds to me like it is conflating
> declaration with use.  I agree that we want the uses not to be cluttered,
> but adding a bit to the declaration doesn't seem harmful if it adds
> something to the usabiity of the API.
>

Just to be perfectly clear, using BGGA closures one can define apply this
way:

class ParallelArray<T> {
    <throws X> void apply({ T => void throws X } proc) throws X { ... }
}

or, using a nominal type

interface Proc<T, throws X> {
    void apply(T t) throws X;
}
class ParallelArray<T> {
    <throws X> void apply(Proc<? super String, ? extends X> proc) throws X {
... }
}

and use it (either version) this way:

ParallelArray<String> pa = ...;
try {
    pa.apply({ String s => doSomethingThatMightThrowSomeException(s); })
} catch (*SomeException* ex) {
    // handle the exception here
}

Admittedly, doing this with anonymous inner classes (or CICE) would be more
painful, as you have to repeatedly call out the thrown exception type, and
it gets worse if you attempt to nest such calls:

ParallelArray<String> pa = ...;
try {
    pa.apply(new Proc<String,*SomeException*>() {
        public void apply(String s) throws *SomeException* {
            doSomethingThatMightThrowSomeException(s);
        }
    });
} catch (*SomeException* ex) {
    // handle the exception here
}

Incidentally, this all works today in the BGGA prototype.

Regards,
Neal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20071228/3b3f87c3/attachment.html 


More information about the Concurrency-interest mailing list