errors

Err is interface that implements a single ft that return string

f, err := os.Open("filename.txt")
if err == nil {
    fmt.Println("f")
} else {
    fmt.Println(err)
    //SAME AS
    fmt.Println(err.Error())
}

Creating Errors

import (
    "errors"
)

myError := errors.New("My error string")

Panic, Defer, and Recover

Defer

Puts a func on the call stack that will be run in reverse order when host ft finishes

Panic

stops execution passing control to deferred fts

Recover

Only available in a defer, catch a panic

Other Examples

Last updated