Go 编程语言中的异常支持
Exception support in Go programming language
一些消息来源说 Go 出于性能原因不支持异常,但其他一些消息说 Google 团队实现了一些。 Go 当前的异常支持是什么?
Go 没有异常,that is a design decision,不基于性能:
We believe that coupling exceptions to a control structure, as in the try-catch-finally idiom, results in convoluted code. It also tends to encourage programmers to label too many ordinary errors, such as failing to open a file, as exceptional.
Go takes a different approach. For plain error handling, Go's multi-value returns make it easy to report an error without overloading the return value. A canonical error type, coupled with Go's other features, makes error handling pleasant but quite different from that in other languages.
一些消息来源说 Go 出于性能原因不支持异常,但其他一些消息说 Google 团队实现了一些。 Go 当前的异常支持是什么?
Go 没有异常,that is a design decision,不基于性能:
We believe that coupling exceptions to a control structure, as in the try-catch-finally idiom, results in convoluted code. It also tends to encourage programmers to label too many ordinary errors, such as failing to open a file, as exceptional.
Go takes a different approach. For plain error handling, Go's multi-value returns make it easy to report an error without overloading the return value. A canonical error type, coupled with Go's other features, makes error handling pleasant but quite different from that in other languages.