I use CMake to create my projects. In the project I use mainly Qt C++ and some MFC functions for hardware interface. Does it make any sense to use try/catch e->ReportError() or some other exception statements in the code?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can of course use exceptions together with Qt. The question is just, how useful they are. As an example, consider the following class
The exception is thrown inside a slot. To catch this exception, you have to wrap the
signal, which triggers the slot, in a
tryblock, e.g.Unfortunately, it is not always possible to use this approach. For example, when you connect
QPushButton::clicked()toThrower::throwException(), clicking the buttonwill cause a crash of the event loop.
You could wrap
QApplication::exec()in atry-block, but when you catch the exception, the GUI is most likely already destructed, so there is no real possibility to recover from an exception.Also have a look at the Qt documention about exception safety.