为什么 Qt 不使用异常处理? [英] Why doesn't Qt use exception handling?

查看:47
本文介绍了为什么 Qt 不使用异常处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have always wondered that since Qt uses almost every C++ feature in the standard and in a wonderful and an innovative way, and whenever it doesn't use a particular feature, it has a perfectly valid and applicable reason for not doing so. In that case, why is it that no Qt classes ever use the throw keyword and throw any exceptions? What is their rationale behind never requiring a try ... catch block in our Qt written code?

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

Personally, I myself don't like it much and never use it whether or not I'm working with Qt and always go with error codes and return values instead of throwing exception objects. But why don't I see a QException class in their documentation? What is the Qt developers viewpoint on this?

推荐答案

主要是由于历史原因.编译器中的异常支持需要相当长的时间才能成熟.引用诺基亚的托比亚斯饥饿:

For historic reasons, mostly. Exception support in compilers took quite some time to mature. Citing Nokia's Tobias Hunger:

当 Qt 启动时,异常对于 Qt 需要支持的所有编译器都不可用.今天我们试图保持 API 的一致性,因此具有不使用异常历史的模块通常不会获得新代码使用异常添加.您会注意到 Qt 的一些新模块中使用了异常."

"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 不使用异常处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆