Solved Exception not caught when thrown within QXmlSimpleReader::parseFile
-
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).
-
Hi! Maybe this helps: Exception Safety
-
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. -
dumb question: where is the solved button???
-
-
@Pradeep-Kumar
strange, not for me - screenshot:
I am logged in as the same user as I started the topic... -
hi this is the fun thing.
First you must select "Ask as Question, then "Solve" comes.
Yes, its stupid :) -
@mrjj
You saved my day :-))