os.Error - string value (Golang)

后端 未结 2 1141

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

2条回答
  •  不思量自难忘°
    2021-02-11 15:35

    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"
    

提交回复
热议问题