gpt4 book ai didi

qt - Qt 为什么不使用异常处理?

转载 作者:行者123 更新时间:2023-12-01 17:15:48 28 4
gpt4 key购买 nike

我一直想知道,由于 Qt 以一种美妙且创新的方式使用了标准中的几乎所有 C++ 功能,并且每当它不使用特定功能时,它都有一个完全有效且适用的理由不这样做。在这种情况下,为什么没有 Qt 类使用 throw 关键字并抛出任何异常?在我们的 Qt 编写的代码中从不需要 try ... catch block 背后的理由是什么?

就我个人而言,我自己不太喜欢它,无论我是否使用 Qt,都不会使用它,并且总是使用错误代码和返回值,而不是抛出异常对象。但为什么我在他们的文档中看不到 QException 类? Qt 开发人员对此有何看法?

最佳答案

主要是出于历史原因。编译器中的异常支持花了相当长的时间才成熟。引用诺基亚的Tobias Hunger :

"When Qt was started exceptions were not available for all the compilers that needed to be supported by Qt. Today we are trying to keep the APIs consistent, so modules that have a history of not using exceptions will generally not get new code using exceptions added. You will notice exceptions are used in some of the new modules of Qt."

我认为这已经概括了一切。

关于qt - Qt 为什么不使用异常处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5548951/

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