0

I have several actions, whose errors I'm trying to catch:

let result: anyhow::Result<()> = {
    foo()?;
    bar()?;
    baz()?;
    quux()
}

If foo(), bar() or baz() return an error, they exit the function prematurely (because of the question marks).

Is there an alternative to the question mark, which just exits the current block, rather than the current function?

If not, how should I structure a large number of sequential potential errors, whose result I need? (I need to handle eight in my code.)

oguz ismail
  • 1
  • 16
  • 47
  • 69
fadedbee
  • 42,671
  • 44
  • 178
  • 308
  • 3
    There are `try` blocks, but are not yet ready - https://doc.rust-lang.org/beta/unstable-book/language-features/try-blocks.html – Svetlin Zarev Aug 17 '21 at 05:37
  • In the meantime you can use compinators to achieve the same effect at the cost of more code: https://stackoverflow.com/questions/68509419/is-it-possible-to-use-operator-in-a-scope/68509583#68509583 – Svetlin Zarev Aug 17 '21 at 05:48

0 Answers0