Some sources says that Go does not support exceptions for performance reasons, but some others says that Google Team implemented a few. What is the current exception support in Go?
1条回答 默认 最新
dsh8009271 2018-07-17 20:17关注Go does not have exceptions, and that is a design decision, not based on performance:
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.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报