gpt4 book ai didi

go - panic 和断言有什么区别?

转载 作者:IT老高 更新时间:2023-10-28 13:07:59 26 4
gpt4 key购买 nike

Go doesn't provide assertions. They are undeniably convenient, but our experience has been that programmers use them as a crutch to avoid thinking about proper error handling and reporting.

但是它有 print and println哪个

panic like print, aborts execution after printing
panicln like println, aborts execution after printing

这和断言不是一回事吗?为什么他们会声称上述内容却感到 panic ?我可以看到它导致了同样的问题,但是在它的末尾添加了一个错误消息,这很容易被滥用。我错过了什么吗?

最佳答案

不,不是。 panic 就像“写然后中止”,而断言就像“测试,如果它是假的,写然后中止”。无论如何,他们无法阻止您执行类似断言的声明。

关于go - panic 和断言有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2165369/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com