Option 3 looks prettiest to me, but I like that in Option 1 the error-raising code comes before the error-handling code (based on experience with other languages). This might not be an issue in practice.

I am not sure how I like Option 3 with a more complex trap block:

  OutOfKittens.trap(|t| {
      OrderFailure.trap(|t| notify_support()).in {
          order_more_kittens();
      }
      UseAardvarksInstead
  }).in {
      do_some_stuff();
      that_might_raise();
      out_of_kittens();
  }

Compare this to some "ideal" syntax:

  protect {
      do_some_stuff();
      that_might_raise();
      out_of_kittens();
  } handle OutOfKittens(t) {
      protect {
          order_more_kittens();
      } handle OrderFailure(t) {
          notify_support();
      }
      UseAardvarksInstead
  )

Gareth
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to