Exception Handling



  • Dear all,

    Analysing the source code of qt-x11-opensource, I could figure out that the exception handling constructs of c++ are not frequently used in the project. Is there any recommendation for not using try-catch statements for handling errors in the project?

    All the best,

    Rodrigo.


  • Moderators

    Hi, welcome to devnet.

    Qt doesn't use exceptions mostly for historical reasons. At the dawn of times, when Qt was born not all target compilers supported them correctly. Now of course things changed but there's always a question of consistency and backward compatibility. Why rewrite something that works and break a lot of software out there while doing it?

    So there's no reason to use or not use exceptions in your own programs that use Qt. Qt itself will not throw exceptions (mostly) but is not entirely exception safe. Some more info "here":http://qt-project.org/doc/qt-5/exceptionsafety.html
    As a rule of thumb if you decide to use exceptions try to keep their scope tight and don't throw across boundaries (outside slots, threads etc.).



  • Dear all, I am conducting a survey about the use of exception handling constructs in C++. I would really appreciate if you could contribute to this research by answering a few questions on the subject.

    The survey is available on-line:

    https://pt.surveymonkey.com/s/exceptionHandling

    All the best,

    Rodrigo.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.