macro

try! — Legacy Result propagation (deprecated)

Historical macro that extracts Ok or returns an Err converted through From. Deprecated since Rust 1.39; prefer the question-mark operator. In Rust 2018 and later try is reserved, so old code requires raw-identifier spelling if retained. Result: Success value or early error return. Expected output (not executed): '12\ntrue\n' Common mistake: Choosing try! in new code or assuming the macro handles Option in the same way as ?.

Formal Syntax & Structure

rust syntaxrust
r#try!(result_expression) // Rust 2018 and later

Working Example

Example Snippetrust
#[allow(deprecated)]fn legacy(s: &str) -> Result<u32, std::num::ParseIntError> {    let n = r#try!(s.parse::<u32>());    Ok(n)}fn modern(s: &str) -> Result<u32, std::num::ParseIntError> {    let n = s.parse::<u32>()?;    Ok(n)}fn main() {    println!("{}", legacy("12").unwrap());    println!("{}", modern("bad").is_err());}
Rust Reference