Standard library / errors

errors.New()

Creates a non-nil error with the supplied message. Two separate calls with identical text produce distinct error values. Expected stdout: 'bad false\n'.

Formal Syntax & Structure

go syntaxgo
func New(text string) error

Parameters & Attributes

NameTypeDescription
textstringMessage returned by Error().

Return Value

error

New non-nil error.

Working Example

Example Snippetgo
package main
import (  "errors"  "fmt")
func main() {  a, b := errors.New("bad"), errors.New("bad")  fmt.Println(a, a == b)}
Go Reference