Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Exception not caught when thrown within QXmlSimpleReader::parseFile
Forum Update on Monday, May 27th 2025

Exception not caught when thrown within QXmlSimpleReader::parseFile

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stryga42
    wrote on 11 Dec 2016, 18:36 last edited by stryga42 12 Dec 2016, 06:55
    #1

    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).

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 11 Dec 2016, 19:07 last edited by
      #2

      Hi! Maybe this helps: Exception Safety

      1 Reply Last reply
      2
      • S Offline
        S Offline
        stryga42
        wrote on 12 Dec 2016, 06:46 last edited by
        #3

        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-thread QCoreApplication::notify works perfectly but is useless for threads, which are internally created later on.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stryga42
          wrote on 12 Dec 2016, 06:58 last edited by
          #4

          dumb question: where is the solved button???

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Pradeep Kumar
            wrote on 12 Dec 2016, 07:01 last edited by
            #5

            Hi,

            @stryga42

            You can find below Topic Tools select and mark as solved.

            Thanks,

            Pradeep Kumar
            Qt,QML Developer

            S 1 Reply Last reply 12 Dec 2016, 07:17
            0
            • P Pradeep Kumar
              12 Dec 2016, 07:01

              Hi,

              @stryga42

              You can find below Topic Tools select and mark as solved.

              Thanks,

              S Offline
              S Offline
              stryga42
              wrote on 12 Dec 2016, 07:17 last edited by stryga42 12 Dec 2016, 07:19
              #6

              @Pradeep-Kumar
              strange, not for me - screenshot:
              screenshot
              I am logged in as the same user as I started the topic...

              M 1 Reply Last reply 12 Dec 2016, 07:20
              0
              • S stryga42
                12 Dec 2016, 07:17

                @Pradeep-Kumar
                strange, not for me - screenshot:
                screenshot
                I am logged in as the same user as I started the topic...

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 12 Dec 2016, 07:20 last edited by mrjj 12 Dec 2016, 07:20
                #7

                @stryga42

                hi this is the fun thing.
                First you must select "Ask as Question, then "Solve" comes.
                Yes, its stupid :)

                S 1 Reply Last reply 12 Dec 2016, 07:21
                1
                • M mrjj
                  12 Dec 2016, 07:20

                  @stryga42

                  hi this is the fun thing.
                  First you must select "Ask as Question, then "Solve" comes.
                  Yes, its stupid :)

                  S Offline
                  S Offline
                  stryga42
                  wrote on 12 Dec 2016, 07:21 last edited by
                  #8

                  @mrjj
                  You saved my day :-))

                  1 Reply Last reply
                  2

                  1/8

                  11 Dec 2016, 18:36

                  • Login

                  • Login or register to search.
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved