From ee4b58c7925a914abac8ebc7a0fc0be0cb6cb0c7 Mon Sep 17 00:00:00 2001 From: frankamp Date: Sat, 30 May 2015 13:31:46 -0700 Subject: [PATCH] Fixes consistency in before/after example The doc indicates that you can replace 'before' with 'after' showing the use of try!. The two examples should be equivalent, but they are not. In the File::create we were inducing a panic before in case of error, not propagating. It is important for newbies (like myself) to understand that try! propagates failures, while unwrap can induce a panic. The other alternative is to make the 'before' File::create also manually handle Err like the other calls. Either way it would be consistent. --- src/doc/trpl/error-handling.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/error-handling.md b/src/doc/trpl/error-handling.md index 7b47559e0fc..2a0e8ed1643 100644 --- a/src/doc/trpl/error-handling.md +++ b/src/doc/trpl/error-handling.md @@ -284,7 +284,7 @@ struct Info { } fn write_info(info: &Info) -> io::Result<()> { - let mut file = try!(File::create("my_best_friends.txt")); + let mut file = File::create("my_best_friends.txt").unwrap(); try!(writeln!(&mut file, "name: {}", info.name)); try!(writeln!(&mut file, "age: {}", info.age));