Skip to content

Commit d1f4993

Browse files
committed
Add basic Unstable Book entry for catch_expr.
1 parent 0c97d6c commit d1f4993

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/doc/unstable-book/src/language-features/catch-expr.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
```

0 commit comments

Comments
 (0)