Skip to content

Commit ee4b58c

Browse files
committed
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.
1 parent ee1ba33 commit ee4b58c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/doc/trpl/error-handling.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ struct Info {
284284
}
285285

286286
fn write_info(info: &Info) -> io::Result<()> {
287-
let mut file = try!(File::create("my_best_friends.txt"));
287+
let mut file = File::create("my_best_friends.txt").unwrap();
288288

289289
try!(writeln!(&mut file, "name: {}", info.name));
290290
try!(writeln!(&mut file, "age: {}", info.age));

0 commit comments

Comments
 (0)