go err

时间:2019-10-25 09:17:00   收藏:0   阅读:77

golang自定义err方案很多

// Errno 代表某种错误的类型 
type Errno int

func (e Errno) Error() string {
    return "errno " + strconv.Itoa(int(e))
}

func main(){
   // 示例3。
    const (
        ERR0 = Errno(0)
        ERR1 = Errno(1)
        ERR2 = Errno(2)
    )
    var myErr error = Errno(0)
    switch myErr {
    case ERR0:
        fmt.Println("ERR0")
    case ERR1:
        fmt.Println("ERR1")
    case ERR2:
        fmt.Println("ERR2")
    }  
}

 

原文:https://www.cnblogs.com/jackey2015/p/11736015.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!