drwjv28028 2019-04-28 02:11
浏览 100
已采纳

func(e * errorString)FormatError(p打印机)(下一个错误)

https://github.com/golang/xerrors/blob/master/errors.go#L29:47

func (e *errorString) FormatError(p Printer) (next error) {
    p.Print(e.s)
    e.frame.Format(p)
    return nil
}

If am not mistaken this always returns nil right ? What is then the purpose of next if it's always nil ?

  • 写回答

1条回答 默认 最新

  • doudi8525 2019-04-28 02:25
    关注

    What is then the purpose of next?


    The FormatError(p Printer) (next error) method satisfies an interface.

    // A Formatter formats error messages.
    type Formatter interface {
        error
    
        // FormatError prints the receiver's first error and returns the next error in
        // the error chain, if any.
        FormatError(p Printer) (next error)
    }
    

    Sometimes we do return a non-nil error.

    func (e *noWrapError) FormatError(p Printer) (next error) {
        p.Print(e.msg)
        e.frame.Format(p)
        return e.err
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 在使用pyecharts时出现问题
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计