val, err := function()
if err != nil {
//handler codes...
}
Error handling consists of 3 key parts, trigger, handler and binding rule. In Go 1, trigger is if err != nil
, handler is a piece of code in {}
, and binding rule is obvious. Handler holds the control flow switch.
Actually, I donot think error handling in Go 1 has any functional problem. The only problem is repetition, especially repetition of triggers. Go 1 allows us to place trigger and assignment in one line, but that does not really solve the problem.