Arc Forumnew | comments | leaders | submitlogin
1 point by rocketnia 4758 days ago | link | parent

Oh yeah, there's something I think would be even more useful than any of these 'errsafe variants:

  (ifreturn result exn (foo)
      do-something-with.result
    an-error-we-expect.exn
      (do prn.exn (do-something-else))
    an-error-we-dont-want-to-propagate.exn
      (err "some better error")
      raise.exn)
  
  (aifreturn (foo)
      do-something-with.it
    an-error-we-expect.it
      (do prn.it (do-something-else))
    an-error-we-dont-want-to-propagate.it
      (err "some better error")
      raise.it)
With a traditional try block, if I want to 'do-something-with the return value only if there isn't an error, the obvious place to do it is right there inside the try block, after the value has been successfully calculated. However, that means the errors thrown by 'do-something-with itself can be caught, which is almost never my intention.

Instead, I go to great lengths with booleans just to avoid doing putting too much inside the try block. What I really want are macros like these.

Meanwhile, the same idea could be beneficial for fixed-syntax languages too:

  try:
      foo()
  then result:
      do_something_with(result)
  except Exception as e
      do_something_else_with(e)
  
  try
  {
      foo();
  }
  then ( Foo result )
  {
      doSomethingWith( result );
  }
  catch ( Exception e )
  {
      doSomethingElseWith( e );
  }