gitee.com/quant1x/gox@v1.21.2/exception/errors.go (about) 1 package exception 2 3 import ( 4 "fmt" 5 ) 6 7 type Throwable interface { 8 error 9 Code() int 10 } 11 12 type Exception struct { 13 Throwable 14 code int 15 message string 16 } 17 18 // New 创建一个新的错误信息, 包含一个状态码和信息 19 func New(code int, message string, a ...any) *Exception { 20 return &Exception{ 21 code: code, 22 message: fmt.Sprintf(message, a...), 23 } 24 } 25 26 // 格式化输出错误信息 27 func (this Exception) Error() string { 28 return fmt.Sprintf("#%d, message=%s", this.code, this.message) 29 } 30 31 func (this Exception) Code() int { 32 return this.code 33 }