Enabling exceptions to Qt project in Visual Studio 2017
-
I'm using Qt with Visual Studio, I'm able to code, compile and run it without any problem.
Now I want to catch some errortry{ //known fail code }catch(...){ qCritical() << "error!";
But the application will crash instead of printing "error" in console! I read online that I need to add -exceptions flag and I tried adding this flag in:
- C\C++ -> Command Line -> Additional Options
- Qt Compilers (Meta-object and resource)
But none of them enabled the exception handling!
What am I wrong? -
I'm using Qt with Visual Studio, I'm able to code, compile and run it without any problem.
Now I want to catch some errortry{ //known fail code }catch(...){ qCritical() << "error!";
But the application will crash instead of printing "error" in console! I read online that I need to add -exceptions flag and I tried adding this flag in:
- C\C++ -> Command Line -> Additional Options
- Qt Compilers (Meta-object and resource)
But none of them enabled the exception handling!
What am I wrong?@TheEnigmist Does your app really crash because of a C++ exception? What error is printed when it crashes?
-
@TheEnigmist Does your app really crash because of a C++ exception? What error is printed when it crashes?
@jsulm Yes, I found out that I can't catch the error "index out of bound". While the code works if I put a simple throw std::runtime_error("error");
My fault! -
@TheEnigmist said in Enabling exceptions to Qt project in Visual Studio 2017:
"index out of bound".
Who should throw an exception here? At least no Qt containers...
-
@TheEnigmist said in Enabling exceptions to Qt project in Visual Studio 2017:
"index out of bound".
Who should throw an exception here? At least no Qt containers...
@Christian-Ehrlicher Yes, I found out that Qt container suppose an index is alredy checked before accessing a list. So I need to check it before and if the index goes over the size of the list raise an exception.
-
@Christian-Ehrlicher Yes, I found out that Qt container suppose an index is alredy checked before accessing a list. So I need to check it before and if the index goes over the size of the list raise an exception.
@TheEnigmist said in Enabling exceptions to Qt project in Visual Studio 2017:
Yes, I found out that Qt container suppose an index is alredy checked before accessing a list
Not really: http://doc.qt.io/qt-5/qlist.html#value-1