by codr7 · 7y ago · 0 comments
Here is my proposal: add restarts [0] as a complement to manual propagation.
[0] https://github.com/codr7/g-fu/blob/master/v1/doc/typical_res...
try() errors can only propagate to the caller. As such, stack unwinding is clear, no memory issues arise, performance is good and locality of error is preserved. Surprise is minimized.
While it may look similar, it's pretty markedly different in important ways.
How is this different from (a) errors bubbling up with a pile of concatenated strings as the only type information or (b) errors not bubbling up because someone decided they would never make a mistake?
The whole value of exceptions, to me, is consistency. The error is guaranteed to propagate in a consistent way up the stack. Static type analysis has a fighting chance of predicting what could ever propagate up the stack, whether checked or unchecked.
Trying to work out out what `err` might be in various situations is an exercise in forensic grepping. Trying to react intelligently and reliably to different types of error is an exercise in hoping nobody changes the error string.
Restarts [0] evaluate the error handler in the throwing scope/environment and the only way out of there is invoking a predefined restart or aborting the program.
[0] https://github.com/codr7/g-fu/blob/master/v1/doc/typical_res...
function X() throws Oops {
okToFail(); // fine if this failure goes up
unexpectedFailure(); // not fine to go up
}
Unfortunately, once you tell the compiler its ok for exeptions to go up, that rule applies to the whole function.Also, you don’t use try everywhere, that’s the point. They could do with some better examples.
So like, checked exceptions?
>Also the error is in the function signature, unlike exceptions.
So like, checked exceptions?
For one, the Go team hasn't invented exceptions, so they don't fit the NIH goals.