hlovatt wrote:
> OK these are valid points. So why not make a new subclass of Throwable
> called Jump that acts like a checked exception, Exception, in Java and
> recommend that people don't catch it (but importantly allow them to
> catch it - see below). I doubt that any mechanism is totally bullet
> proof, so I don't see a problem with a simple recommendation in the
> Java context. For other languages it may be appropriate to enforce
> that Jump cannot be caught in that language. I am deliberately putting
> forward a Java and a non-Java viewpoint since in the ideal world
> multiple languages can co-exist and call each other and therefore
> control flow needs to have identical semantics in all cases. If it is
> a specific non-Java feature then a method that uses it cannot be
> called from Java, if on the other hand it is like a checked exception
> then Java can call it (and catch or throw Jump if that is what it
> takes to deal with the non-Java method).
Full disclosure: I'm rapidly losing respect for checked exceptions.
That said, I think making Jump a checked exception is a *terrible* way
to go. Not only would it require adding the checked exception to every
single API we want to closure-enable, it requires that anywhere we want
to have non-local flow control in play we have to explicitly declare it.
Even worse, it requires that all intermediate APIs that may not even
care about non-local flow control would also have to declare they throw
jumps even if they're just passing a closure on to a deeper method.
// foo does the actual call...
void foo(Closure c1) {
c1.call();
}
// ...but bar, simply by virtue of accepting a closure, would have to
// declare that it throws Jump
void bar(Closure c2) {
foo(c2);
}
Essentially, it would require that all methods dealing with closures
must throw Jump, even if the closures they're passed never use non-local
flow control, simply because *they might*.
I think the detail you're missing here is that non-local flow control is
not a feature of the closure-friendly API you are calling, it's a
feature of the closure you're passing to it. Therefore it makes no sense
to require that all closure-accepting methods throw Jump, since in many
(most?) cases they won't, nor will they typically care if non-local
Jumps pass through them.
- Charlie
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---