Telegram Founder Durov Allowed to Temporarily Leave France
barrons.com3 pointsby tail_exchange0 comments
result := InvokeWithErrorLogger(
func (err error) { // Error handler
incrementMetric("foo")
log.Error("bar")
},
addTwoNumbers, a, b,
)
But the problem is that this approach is not better than just writing this, which doesn't need any new fancy addition to the language: result, err := addTwoNumbers(a, b)
if err != nil {
incrementMetric("foo")
log.Error("bar")
return fmt.Errorf("addTwoNumbers(%d, %d) = %v", a, b, err)
}
Hence why all the proposals ended up dying with the lack of traction. result, err := addTwoNumbers(a, b)
if err != nil {
return fmt.Errorf("addTwoNumbers(%d, %d) = %v", a, b, err)
}
This way you can enrich the error message and say what was passed to the function. If you try to abstract this logic with a "Handle" function, you'll just create a mess. You'll save yourself the time of writing an IF statement, but you'll need a bunch of arguments that will just make it harder to use.