error-concept
anyhow!: construct a diagnostic error
Create an ad hoc error value with a message. The macro by itself does not return from the enclosing function. Requires anyhow = "=1.0.104" in Cargo.toml. See the staged dependency project. Expected stdout (not executed): limit is 5 Expected stderr: (empty) Expected exit: success Common mistake: Confusing construction with an early return.
Formal Syntax & Structure
rust syntaxrust
anyhow::anyhow!(format, args...)Working Example
Example Snippetrust
fn main() { let limit = 5; let error = anyhow::anyhow!("limit is {limit}"); println!("{error}");}