[E-Lang] when-catch-finally (was: pending revision of E in a
Walnut)
Karp, Alan
alan_karp@hp.com
Thu, 23 Aug 2001 09:08:53 -0700
MarkM wrote:
>
> Now that this is control-flow oriented, there is a new
> counter-intuitive
> issue: An exception thrown during the evaluation of the
> expression in the
> "when (...) ->" head is *not* caught by these catch clauses,
> but is rather
> thrown in the original context. I think it needs to be this
> way, but people
> will find it surprising.
>
Well, if a broken reference is an exception, then when(...) can move into
its block whenever a reference is either resolved or broken. That block can
contain a try-catch with an exception thrown on an attempt to use a broken
reference. For example,
when (nextCar <- moveTo(toX,toY)) -> done(moving) {
try {
println(nextCar name + " arrived, next car to start
moving")
} catch BrokenReferenceException e {
println("car died: " + e)
} catch Exception e {
println(e + " happens.")
} finally {
moveRemainingCars()
}
}
which looks a lot like MarkM's example
Ref whenResolved(xVow, def done(temp) {
try {
def tempProb := Ref optProblem(temp)
if (Ref isBroken(temp)) {
throw(Ref optProblem(temp)) // Explicit throw not needed
(AHK)
}
def x := temp
doSomething(x)
} catch prob { // Should be multiple catch blocks
(AHK)
handle(prob)
} finally {
doLast()
}
})
_________________________
Alan Karp
Principal Scientist
Decision Technology Department
Hewlett-Packard Laboratories MS 1U-3
1501 Page Mill Road
Palo Alto, CA 94304
(650) 857-3967, fax (650) 857-6278
https://ecardfile.com/id/Alan_Karp
http://www.hpl.hp.com/personal/Alan_Karp/