Skip to content

Instantly share code, notes, and snippets.

PeterRK / package level
Last active Oct 16, 2018
package level generics
View package level

Package level generics may look less confusing.

package abc(Key,Value)

contract CompileCheck(a1 Key, a2 Value) {

type Pair struct {
	K Key
PeterRK / Simple Error Handling for Go
Last active Dec 8, 2020
Simple Error Handling for Go 2
View Simple Error Handling for Go

Key Parts of Error Handling

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.