首页 > 其他 > 详细

golang.erros

时间:2020-04-29 20:17:33      阅读:90      评论:0      收藏:0      [点我收藏+]

 

 

package builtin

type error interface { Error() string }


######################
error接口定义

 

 

package errors

// 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 {
    return &errorString{text}
}

// errorString is a trivial implementation of error.
type errorString struct {
    s string
}

func (e *errorString) Error() string {
    return e.s
}


######################################################
1.定义一个包含一个字符串的类errorString,并实现erro接口方法

2.创建一个errorString对象

 


package http


var (
ErrBodyNotAllowed = errors.New("http: request method or response status code does not allow body") ErrHijacked = errors.New("http: connection has been hijacked") ErrContentLength = errors.New("http: wrote more than the declared Content-Length") ErrWriteAfterFlush = errors.New("unused") )

########################################################################################################
erro使用:
直接使用errors包的New方法创建


 

golang.erros

原文:https://www.cnblogs.com/igoodful/p/12804272.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!