File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
src/doc/unstable-book/src/language-features Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -5,3 +5,26 @@ The tracking issue for this feature is: [#31436]
55[ #31436 ] : https://github.com/rust-lang/rust/issues/31436
66
77------------------------
8+
9+ The ` catch_expr ` feature adds support for a ` catch ` expression. The ` catch `
10+ expression creates a new scope one can use the ` ? ` operator in.
11+
12+ ``` rust
13+ #![feature(catch_expr)]
14+
15+ use std :: num :: ParseIntError ;
16+
17+ let result : Result <i32 , ParseIntError > = do catch {
18+ Ok (" 1" . parse :: <i32 >()?
19+ + " 2" . parse :: <i32 >()?
20+ + " 3" . parse :: <i32 >()? )
21+ };
22+ assert_eq! (result , Ok (6 ));
23+
24+ let result : Result <i32 , ParseIntError > = do catch {
25+ Ok (" 1" . parse :: <i32 >()?
26+ + " foo" . parse :: <i32 >()?
27+ + " 3" . parse :: <i32 >()? )
28+ };
29+ assert! (result . is_err ());
30+ ```
You can’t perform that action at this time.
0 commit comments