Go - Error Handling (err)

Card Puncher Data Processing

About

Go has no exception mechanism. An error object must be returned by the function and checked.

Snippet

Go allows a simple statement such as a local variable declaration to precede the if condition. Combining the statements is shorter and reduces the scope of the variable err.

This two statement are equivalent:

if err := r.ParseForm(); err != nil {
	log.Print(err)
       //log.Fatal(err)
}

// Equivalent to
err := r.ParseForm()
if err != nil { 
    log.Print( err) 
} 

Documentation / Reference







Share this page:
Follow us:
Task Runner