# std::try! [−]

    macro_rules! try {
        ( $ expr : expr ) => { ... };
    }

Helper macro for unwrapping `Result` values while returning early with an error if the value of the expression is `Err`. Can only be used in functions that return `Result` because of the early return of `Err` that it provides.

# Examples

fn main() { use std::io; use std::fs::File; use std::io::prelude::*; fn write_to_file_using_try() -> Result<(), io::Error> { let mut file = try!(File::create("my_best_friends.txt")); try!(file.write_all(b"This is a list of my best friends.")); println!("I wrote to the file"); Ok(()) } // This is equivalent to: fn write_to_file_using_match() -> Result<(), io::Error> { let mut file = try!(File::create("my_best_friends.txt")); match file.write_all(b"This is a list of my best friends.") { Ok(_) => (), Err(e) => return Err(e), } println!("I wrote to the file"); Ok(()) } }

    use std::io;
    use std::fs::File;
    use std::io::prelude::*;

    fn write_to_file_using_try() -> Result<(), io::Error> {
        let mut file = try!(File::create("my_best_friends.txt"));
        try!(file.write_all(b"This is a list of my best friends."));
        println!("I wrote to the file");
        Ok(())
    }
    // This is equivalent to:
    fn write_to_file_using_match() -> Result<(), io::Error> {
        let mut file = try!(File::create("my_best_friends.txt"));
        match file.write_all(b"This is a list of my best friends.") {
            Ok(_) => (),
            Err(e) => return Err(e),
        }
        println!("I wrote to the file");
        Ok(())
    }

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize`)