From d1f499309979fb53f4fa6d791cbfac803431579d Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 20 May 2017 11:47:51 -0400 Subject: [PATCH] Add basic Unstable Book entry for `catch_expr`. --- .../src/language-features/catch-expr.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/doc/unstable-book/src/language-features/catch-expr.md b/src/doc/unstable-book/src/language-features/catch-expr.md index 44eb2a6dd4fd..fbd213dca569 100644 --- a/src/doc/unstable-book/src/language-features/catch-expr.md +++ b/src/doc/unstable-book/src/language-features/catch-expr.md @@ -5,3 +5,26 @@ The tracking issue for this feature is: [#31436] [#31436]: https://github.com/rust-lang/rust/issues/31436 ------------------------ + +The `catch_expr` feature adds support for a `catch` expression. The `catch` +expression creates a new scope one can use the `?` operator in. + +```rust +#![feature(catch_expr)] + +use std::num::ParseIntError; + +let result: Result = do catch { + Ok("1".parse::()? + + "2".parse::()? + + "3".parse::()?) +}; +assert_eq!(result, Ok(6)); + +let result: Result = do catch { + Ok("1".parse::()? + + "foo".parse::()? + + "3".parse::()?) +}; +assert!(result.is_err()); +```