logoalt Hacker News

Pxtllast Tuesday at 11:25 PM1 replyview on HN

Obviously I'm being terse for argument.

You can easily imagine

  InvokeWithErrorLogger(fn, fnparam, log)
or

  InvokeWithErrorAnnotator(fn, fnparam, annotatorFn)
Or any other common error-handling pattern.

Replies

tail_exchangelast Wednesday at 2:07 AM

Perhaps something like this?

    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.