blog

S E A N K . H . L I A O

error handling

if err != nil {
        // handle error
}

Error handling seems to be a recurring theme in go, but most proposals get nowhere.

proposals

baseline code

x, err := foo()
if err != nil {
        return nil, wrap(err)
}
handling

note: almost all the ones that claim to use "plain functions" as error handlers have an implicit nonlocal return

predeclared handlers
call specific handler
wrapping

some rely on wrap being smart and passing through nil (so not fmt.Errorf),

return

can use defer for wrapping

try..catch
others