go语言之进阶篇error接口的使用

1、error接口的使用

示例:

package main

import "fmt"
import "errors"

func main() {
	//var err1 error = fmt.Errorf("%s", "this is normol err")
	err1 := fmt.Errorf("%s", "this is normal err1")
	fmt.Println("err1 = ", err1)

	err2 := errors.New("this is normal err2")
	fmt.Println("err2 = ", err2)
}

执行结果:

err1 =  this is normal err1
err2 =  this is normal err2

  

 

原文地址:https://www.cnblogs.com/nulige/p/10254276.html