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 Handling, Throwing Exception and Try/Catch blocks
Forum Updated to NodeBB v4.3 + New Features

Exception Handling, Throwing Exception and Try/Catch blocks

Scheduled Pinned Locked Moved General and Desktop
37 Posts 7 Posters 74.2k Views 1 Watching
  • 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.
  • G Offline
    G Offline
    giesbert
    wrote on last edited by
    #28

    QEventLoop :-))
    And throwing exceptions via libraries is not the problem. But perhaps the QApplication eventloop catches them? I didn't look at the QtCode for that up to now.

    Nokia Certified Qt Specialist.
    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #29

      I catch the exceptions in the methods, where I call the lib's functions. In my special case, there is no event loop that can make things bad.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • W Offline
        W Offline
        Wolf P.
        wrote on last edited by
        #30

        Gerolf, QEventLoop has no signals and no virtual function, so... In this issue I need to familiarize myself first...
        (and: I don't think that you can throw an exception through a binary dynamic link library (with a C API).)

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #31

          You're right. C does not provide exceptions. You would have to write a C++ wrapper that adds this and that probably makes the API more OO-like (that's what the ImageMagick/GraphicsMagick guys did).

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • W Offline
            W Offline
            Wolf P.
            wrote on last edited by
            #32

            [quote author="Volker" date="1292253297"]I catch the exceptions in the methods, where I call the lib's functions. In my special case, there is no event loop that can make things bad. [/quote] You're right. But If you forget to handle a particular exception your program crashes.
            Of course it should be terminated immidiately, but gracefully.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #33

              That part of the program is only very small. Basically only one class that uses the lib, and every exception that can be thrown is caught and handled in our case. But I agree, that can be hard to handle all together.

              I personally like the concept of exceptions - you can throw them and whoever is responsible catches them and handles the condition. Althoug I never used them in C++ on my own (only in Java), as there are too many pitfalls at the moment.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #34

                Dlls can use exceptions, wolf, if they are C++ dlls. And I don't think, that you create C dlls if you are using Qt, do you? My dlls are normally C++ dlls which export C++ classes. There it could be done, but I don't do it.
                And QEventLoop handles asynchronous signals, as QueuedSignals are in fact events :-)

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  Wolf P.
                  wrote on last edited by
                  #35

                  For clarity: I am not in the least interested to write DLLs in C myself. I meant pre-existing DLLs. Try to throw an exception in a Windows callback and you'll see what I was talking about. (Sometimes you have to code against a Windows API.)

                  I'm sorry that I have expressed this somewhat misleading.

                  1 Reply Last reply
                  0
                  • D DenisKormalev

                    cazador7907, exception-way or errno-way are equal ways. I can't say that one is better than another. They are simply different. Qt chose errno-way at the beginning and uses it now.

                    P Offline
                    P Offline
                    pip010
                    wrote on last edited by
                    #36

                    @DenisKormalev said in Exception Handling, Throwing Exception and Try/Catch blocks:

                    exception-way or errno-way are equal ways. I can't say that one is better than another. They are simply different. Qt chose errno-way at the beginning and uses it now.

                    NOT THEY ARE NOT!
                    exception are structured way of both rise the error and handle the error
                    return codes do not dictate how you handle (the mechansim) , you might even not handle it!, try doing the same with exceptions ;)

                    1 Reply Last reply
                    0
                    • G giesbert

                      This means, no exceptions from slots and event handlers. Or re-implement that function, but you can't handle them in the main if they are thrown in the event loop. And what to do in event loops in threads?

                      P Offline
                      P Offline
                      pip010
                      wrote on last edited by
                      #37

                      @giesbert tier down the application obviously ... exceptions are exceptional ...

                      1 Reply Last reply
                      0

                      • Login

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