본문 바로가기
Go/Packages

[Go] Package errors

by llHoYall 2020. 10. 29.

Package errors implements functions to manipulate errors.

Methods

New

New returns an error that formats as the given text.

Each call to New returns a distinct error value even if the text is identical.

func New(text string) error

Usages

package main

import (
  "errors"
  "log"
)

func main() {
  err := errors.New("error: my error")
  if err != nil {
    log.Fatal(err)
  }
}
// error: my error

'Go > Packages' 카테고리의 다른 글

[Go] Package log  (0) 2020.11.30
[Go] Package bufio  (0) 2020.10.31
[Go] Package math  (0) 2020.10.27
[Go] Package strconv  (0) 2020.10.26
[Go] Package strings  (0) 2020.10.26

댓글