Exception not caught when thrown within QXmlSimpleReader::parseFile
-
wrote on 11 Dec 2016, 18:36 last edited by stryga42 12 Dec 2016, 06:55
I use QXmlSimpleReader together with a handler class based on QXmlDefaultHandler to read an xml file during application startup. I do some semantic checks on the xml within my own startElement implementation and throw an exception if something unexpected is found. Something like:
throw Ex(QString("Hal::xmlFactory: type <%1> not known").arg(typeStr));
I would like to catch those exceptions outside the parseFile call, that is in the ctor of my application instance. But my catch block does not catch anything. Even the "last resort" catch(...) in main does not catch:
try { MyApp a(argc, argv); res=app.exec(); } catch(Ex & ex) { logit(LOG_DAEMON | LOG_CRIT, VERSION_STR" Exception catched in main: %d %s\n", ex.getCode(), ex.getMessage().toUtf8().data()); } catch(...) { logit(LOG_DAEMON | LOG_CRIT, VERSION_STR" Exception catched in main\n"); }
If I catch directly in startElement (which doesn't make much sense, I tried it just as a test of my syntax) everything works as expected.
Is there some "thread-magic" going on inside QXmlSimpleReader? Or do I miss something else here?I throw an instance of a home-brew exception class and I catch a reference to this class. Everything is compiled into one executable. Qt5.6 on linux (actually a Raspberry Pi, so it is more or less Debian but I hope it is not a platform issue).
-
wrote on 11 Dec 2016, 19:07 last edited by
Hi! Maybe this helps: Exception Safety
-
wrote on 12 Dec 2016, 06:46 last edited by
Good point:
"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:"
The most reasonable explanation is that the xml reader creates its own threads directly or via asynchronous slots. If one of those threads die because of an un-catched exception the runtime will shut down the whole process.
Although this is bad news from an architectural point of view it explains the current behavior.
My X-mas wish to Qt: Create an interface where I can insert try/catch blocks so that the signal/slot mechanism can be made compatible with exceptions. For the GUI-threadQCoreApplication::notify
works perfectly but is useless for threads, which are internally created later on. -
wrote on 12 Dec 2016, 06:58 last edited by
dumb question: where is the solved button???
-
wrote on 12 Dec 2016, 07:01 last edited by
-
wrote on 12 Dec 2016, 07:17 last edited by stryga42 12 Dec 2016, 07:19
@Pradeep-Kumar
strange, not for me - screenshot:
I am logged in as the same user as I started the topic... -
@Pradeep-Kumar
strange, not for me - screenshot:
I am logged in as the same user as I started the topic...Lifetime Qt Championwrote on 12 Dec 2016, 07:20 last edited by mrjj 12 Dec 2016, 07:20hi this is the fun thing.
First you must select "Ask as Question, then "Solve" comes.
Yes, its stupid :) -
hi this is the fun thing.
First you must select "Ask as Question, then "Solve" comes.
Yes, its stupid :)
1/8