Go 错误 return 模式的名称是什么?

What is the name of Go error return pattern?

Go 不支持 try-catch,相反,用于错误处理的 Go 编码风格是 return 一个错误以及潜在的有效值。如果错误符合 error 接口的实现,错误将被设置,否则将被设置为 nil.

查看流畅的签名:

func Open(name string) (file *File, err error)

我想知道这个“错误处理”模式的名称。

我认为您要查找的内容在文献中被命名为 status return。 Golang 只是通过考虑将错误(或错误状态)定义为程序中遇到的不需要和不寻常的情况来实现它。

同时已经在 2003 (six years before Golang was launched) Ned Batchelder wrote about the benefits of Exceptions vs Status Returns (in this case focused on C++) by pointing out some benefits as cleaner code, Joel Spolsky also showed his point of view, but in this case in favour of the status' return opposed to Exceptions.

在 2014 年创建 Go 之后,Martin Fowler also wrote about returning errors in form of Notifications 而不是抛出异常。