PDA

View Full Version : I don't catch exception in Qt



Pechkin
29th April 2018, 08:38
I've encountered a big surprise for me.
My program doesn't catch any exception (in particully in main function ) when qt libraries have been included.
I googled this problem and didn't find an answer.
Please explain me:
1) Why this happens ?
2) How to bypass this ? I use a combination of libraries in software development (stl, boost, opencv) and i cant develop software, applying ONLY QT.
Details:
QT version - 5.2
Mingw 4.8 and 6.02

.pro file


#-------------------------------------------------
#
# Project created by QtCreator 2018-04-28T23:53:47
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = qt_eception
TEMPLATE = app


SOURCES += main.cpp

HEADERS +=

FORMS +=


main.cpp


#include <QApplication>

#undef main
int main(int argc, char *argv[])
{

try
{
QApplication a(argc, argv);
throw "ex";
}
catch(...)
{
// Do Nothing
}
return 0;
}

12813

high_flyer
2nd May 2018, 14:18
what happens if you output something to the console in your catch section? (and don't forget to add a return value as well since main needs it)

At the moment its hard to say if you re not catching anything since your catch section is not doing anything.
The fact your screenshot shows that the application existed with an error suggests to me the exception is thrown, but since you didn't do anything with it, it is propagated all the way up, and since nothing else deals with it, your app simply exits with an error.