4 ms·
I don't actually mind writing the above and adding context, but let's brainstorm some syntax that does the same thing without being verbose. How about something
by lalaithion 5y ago
I don't actually mind writing the above and adding context, but let's brainstorm some syntax that does the same thing without being verbose. How about something like:
$variable1 := try $function_call_which_returns_two_values except $variable2: $expression_which_has_error_type
which is automatically desugared to
$variable1, $variable2 := $function_call_which_returns_two_values
if $variable2 != nil {
return ($zero_values_for_other_return_types, )* $expression_which_has_error_type
}
- mseepgood 5y ago> let's brainstorm some syntax Don't forget to check if someone else already had the same idea: https://seankhliao.com/blog/12020-11-23-go-error-handling-proposals/ https://seankhliao.com/blog/12020-11-23-go-error-handling-pr...
- morelisp 5y agohttps://github.com/golang/go/issues/32437 https://github.com/golang/go/issues/32437
- lalaithion 5y agoThe try syntax proposed there and in other places returns the error unwrapped, which is a no-go for me. I wrap every error that I return from every function.
- encoderer 5y agoOh can I see how you do it?
- camkego 5y agoPlease share articles/blog posts! I would guess there are newer articles about best practices for Go error handling, other than the great articles by Dave Cheney. https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully https://dave.cheney.net/2016/04/27/dont-just-check-errors-ha...