Is it possible to handle multiple different errors at once instead of individually in Rust without using additional functions? In short: what is the Rust equivalent to a Try-Catch statement?
A similar feature was suggested back in 2016, but I don't know what came of it.
For example, doing something like this:
try {
do_step_1()?;
do_step_2()?;
do_step_3()?;
// etc.
} catch {
alert_user("Failed to perform necessary steps");
}
Instead of:
match do_steps() {
Ok(_) => (),
_ => alert_user("Failed to perform necessary steps")
}
// Additional function:
fn do_steps() -> Result<(), Error>{
do_step_1()?;
do_step_2()?;
do_step_3()?;
// etc.
Ok(())
}
My program has a function which checks a variety of different places in the registry for different data values and returns some aggregate data. It would need to use many of these try-cache statements with try-catch inside of other try-catch inside of loops.