How to catch exceptions in Qt?

前端 未结 3 1199
青春惊慌失措
青春惊慌失措 2021-02-01 18:05
try
{  // `count()` throws exception
  connect(thread, SIGNAL(started()), engine, SLOT(count()));  
}
catch(const X& e)
{}

As of Qt-5, I get follow

3条回答
  •  半阙折子戏
    2021-02-01 18:18

    You can try this for an example, to see that your solution is good:

    int f()
    {
        throw 1;
        return 5;
    }
    
    void g(int x)
    {
        cout << x << endl;
    }
    
    int main()
    {
        try {
                g(f());
        }catch(int)
        {
            cout << "Caught exception" << endl;
        }
    }
    

提交回复
热议问题