On Tue, May 29, 2012 at 7:57 AM, Niko Matsakis <[email protected]> wrote:
> In general it seems there are three classes of errors
>
> - globally unrecoverable (just call `fail`)
> - locally unrecoverable (return a `result<X,Y>` type)
> - recoverable (pass in handler or error reporter)
If you have closures with nonlocal returns, callback handlers could
work in both the locally unrecoverable and recoverable cases. Instead
of returning a result<X,Y> type, the function could return the result
of calling its handler, with the handler having the ability to jump
out if a result value doesn't make sense. If a function can't handle a
condition locally and wants to pass it upwards, it can take a callback
of its own and call it for those cases, and that callback in turn
could jump out into its own scope if necessary.
---
fn foo(on_error) {
let res1 = first_thing() {|| goto local_handler; }; // handle
unrecoverable condition locally
let res2 = second_thing() {|| on_error() }; // pass the buck
let res3 = third_thing() {|| alternative_third_thing() }; //
handle recoverable condition
ret combination_of(res1, res2, res3);
local_handler:
ret alternate_thing();
}
---
A somewhat more nuts-and-bolts implementation of exceptions, I guess.
I know arbitrary NLRs in closures can't be handled generally without
affecting performance and that break/cont in for loops are handled
specially, so maybe that rules this approach out.
-Joe
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev