duanjian7617 2018-07-17 20:01
浏览 72
已采纳

Go编程语言中的异常支持

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?