Skip to content
Zelenko edited this page May 1, 2019 · 1 revision

Check for specific package related errors:

Define an error value in a library

package fruits

var NoMorePumpkins = errors.New("No more pumpkins")

Do not create errors with errors.New anywhere in the code but return the predefined value whenever error occurs and then you can do the following:

package shop

if err == fruits.NoMorePumpkins {
     ...
}
Clone this wiki locally