buzz icon indicating copy to clipboard operation
buzz copied to clipboard

Migrate to error return value instead of exceptions

Open giann opened this issue 2 years ago • 0 comments

  • We already have an available tag for errors in Value
  • The parsing and type checking would not be impacted
  • We could get rid of setjmp/longjmp
  • Throwing and returning becomes the same thing
  • try/catch would need to be removed
  • Introduce try to be explicit when we propagate errors. This new keyword is required because we will have to implement a new bytecode that returns if an error is raised.
var another = try couldFail(); | return the error if fails
var again = couldFail() catch defaultValue; | default if fails
  • New syntax to handle error based on its type to make up for the removed try/catch
var value = couldFail() catch {
   Unexpected -> defaultValue,
   else -> panic("you lost me")
}
  • Additionally for this to be really useful we would need https://github.com/buzz-language/buzz/issues/105 so we could write
var value = couldFail() catch {
   Unexpected -> do {
       | ... some complex things

       break newValue;
   },
   else -> panic("you lost me")
}

giann avatar Nov 06 '23 11:11 giann