du512926 2015-05-11 21:21
浏览 59
已采纳

Go是否有标准的Error变量?

Just started using Golang. I think that it is idiomatic to declare an error variable and use it in your error structure to determine what went wrong, as is done in strconv.go. There, ErrRange and ErrSyntax is declared, and when appropriate, references to those are stored in NumError structs when they return. I think that the reason is because then the address of the reference to the error stored in NumError can be compared with the ErrRange and ErrSyntax variables to determine which type of error was returned.

Are there "standard" such declared error types? In Java, for example, you have things like java.lang.IllegalArgumentException. Is there, for instance, ErrArgument or ErrUnsupportedOperation that I can use in my own code instead of creating new error variables that mean the same thing every time?

  • 写回答

3条回答 默认 最新

  • dongpao1873 2015-05-11 21:28
    关注

    No, there aren't. Just provide intelligible errors instead of generic ones. What information does a IllegalArgument transport? Not much, not enough.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀