core: add condition.raise_default.
This commit is contained in:
parent
1048f9abfa
commit
a605416bb4
@ -20,12 +20,18 @@ fn trap(&self, h: &self/fn(&T) ->U) -> Trap/&self<T,U> {
|
||||
}
|
||||
}
|
||||
|
||||
fn raise(t:&T) -> U {
|
||||
fn raise(t:&T) -> U {
|
||||
do self.raise_default(t) {
|
||||
fail ~"Unhandled condition";
|
||||
}
|
||||
}
|
||||
|
||||
fn raise_default(t:&T, default: fn() -> U) -> U {
|
||||
unsafe {
|
||||
match task::local_data::local_data_pop(self.key) {
|
||||
None => {
|
||||
debug!("Condition.raise: found no handler");
|
||||
fail
|
||||
default()
|
||||
}
|
||||
|
||||
Some(handler) => {
|
||||
@ -134,7 +140,6 @@ fn nested_trap_test_outer() {
|
||||
trouble(1);
|
||||
}
|
||||
|
||||
|
||||
assert outer_trapped;
|
||||
}
|
||||
|
||||
@ -174,8 +179,25 @@ fn nested_reraise_trap_test_outer() {
|
||||
nested_reraise_trap_test_inner();
|
||||
}
|
||||
|
||||
|
||||
assert outer_trapped;
|
||||
}
|
||||
|
||||
}
|
||||
#[test]
|
||||
fn test_default() {
|
||||
let sadness_condition : Condition<int,int> =
|
||||
Condition { key: sadness_key };
|
||||
|
||||
let mut trapped = false;
|
||||
|
||||
do sadness_condition.trap(|j| {
|
||||
debug!("test_default: in handler");
|
||||
sadness_condition.raise_default(j, || {trapped=true; 5})
|
||||
}).in {
|
||||
debug!("test_default: in protected block");
|
||||
trouble(1);
|
||||
}
|
||||
|
||||
assert trapped;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user