简体   繁体   中英

Qt exception handling - try catch

I working with qt, I have a big project with gui and several threads.

I want to add exaption handling. I googled it and didn't find any tutorial or some relevant answer.

In some sites I read that qt not support try catch.

Is qt support try catch? Or some error handling? If yes, can some one give some direction or tutorial?

Tank you.

You're not allowed to throw an exception through a signal-slot invocation. Everything else you want to do with exceptions in a Qt application is allowed.

http://doc.qt.io/qt-5/exceptionsafety.html#signals-and-slots

Throwing an exception from a slot invoked by Qt's signal-slot connection mechanism is considered undefined behaviour, unless it is handled within the slot.

class MyClass : public QObject
{
    Q_OBJECT
public slots:
    void mySlot()
    {
        throw std::logic_error(""); // Undefined behavior when invoked by a signal
    }
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM