os.Error - string value (Golang)

后端 未结 2 826
刺人心
刺人心 2021-02-11 15:30

How do I get the string value of os.Error? ie. assign to a variable.

2条回答
  •  孤城傲影
    2021-02-11 15:51

    For example,

    package main
    
    import (
        "errors"
        "fmt"
    )
    
    func main() {
        err := errors.New("an error message")
        s := err.Error()
        fmt.Printf("type: %T; value: %q\n", s, s)
    }
    

    Output:

    type: string; value: "an error message"
    

提交回复
热议问题