Go - Error Handling (err)

Card Puncher Data Processing


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


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 {

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

Documentation / Reference

Share this page:
Follow us:
Task Runner