Why doesn't Qt use exception handling?

前端 未结 3 487
[愿得一人]
[愿得一人] 2020-12-03 06:20

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 featur

相关标签:
3条回答
  • 2020-12-03 06:53

    If you google for "qt exceptions" you will get lot of discussions about this topic. Here is an "official" answer:

    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.

    If you look for exception in the index of assistant (i.e. in the Qt documentation) you will find some exception classes, e.g. QtConcurrent::Exception.

    0 讨论(0)
  • 2020-12-03 07:02

    You can read a nice, mostly civilized debate about exceptions here on the KDE devel mailinglist. Since KDE and QT are related I assume the same issues apply, which (if I read the thread correctly) can be summarized as:

    • Exceptions have performance issues depending on compiler.
    • Shielding users of the library from the obligation to use exceptions (by not throwing them from the library)
    • Issues around the spec for exceptions in C++
    0 讨论(0)
  • 2020-12-03 07:12

    For historic reasons, mostly. Exception support in compilers took quite some time to mature. Citing Nokia's 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."

    I think that sums it up pretty much.

    0 讨论(0)
提交回复
热议问题