Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Including Throwing Exceptions classes to NOEXCEPT project

Including Throwing Exceptions classes to NOEXCEPT project

Scheduled Pinned Locked Moved Solved C++ Gurus
cryptoppexceptionsnoexceptc++
14 Posts 4 Posters 4.5k 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.
  • K Offline
    K Offline
    Kofr
    wrote on 8 Jan 2018, 10:56 last edited by
    #1

    I want to include classes to my noexcept project which throw exceptions (I say about cryptopp).
    After that my project can not be built.
    How to leave the project noexcept when continue using cryptopp with exceptions?
    What technics exist to make class noexcept? (hope there is any besides direct deleating throwing code in original classes)

    P K 2 Replies Last reply 8 Jan 2018, 11:20
    0
    • K Kofr
      8 Jan 2018, 10:56

      I want to include classes to my noexcept project which throw exceptions (I say about cryptopp).
      After that my project can not be built.
      How to leave the project noexcept when continue using cryptopp with exceptions?
      What technics exist to make class noexcept? (hope there is any besides direct deleating throwing code in original classes)

      P Offline
      P Offline
      Paul Colby
      wrote on 8 Jan 2018, 11:20 last edited by
      #2

      Hi @Kofr,

      Can you explain what you mean by "can not be built"? Are you saying you get compilation errors? If so, can you show us the errors you get?

      I'm not entirely sure what you're asking, but I think the general pattern for using code that may throw exceptions within noexect functions is simply to catch all exceptions, and handle them within the function. Something like:

      void myFunction() noexcept
      {
          // don't do anything here that could possibly throw.
      
          try {
              // do something with cryptopp, or other functions that might throw.
          } catch (const some-specific-exception-type &e) {
              // handle the exception
          } catch (const some-other-exception-type &e) {
              // handle the exception
          } catch (...) {
              // handle unknown exceptions
          }
      
          // don't do anything here that could possibly throw.
      }
      

      Cheers.

      K 1 Reply Last reply 8 Jan 2018, 16:54
      2
      • P Paul Colby
        8 Jan 2018, 11:20

        Hi @Kofr,

        Can you explain what you mean by "can not be built"? Are you saying you get compilation errors? If so, can you show us the errors you get?

        I'm not entirely sure what you're asking, but I think the general pattern for using code that may throw exceptions within noexect functions is simply to catch all exceptions, and handle them within the function. Something like:

        void myFunction() noexcept
        {
            // don't do anything here that could possibly throw.
        
            try {
                // do something with cryptopp, or other functions that might throw.
            } catch (const some-specific-exception-type &e) {
                // handle the exception
            } catch (const some-other-exception-type &e) {
                // handle the exception
            } catch (...) {
                // handle unknown exceptions
            }
        
            // don't do anything here that could possibly throw.
        }
        

        Cheers.

        K Offline
        K Offline
        Kofr
        wrote on 8 Jan 2018, 16:54 last edited by
        #3

        @Paul-Colby thank you for the answer.
        I compile with use qmake CONFIG += exceptions_off.
        This is same as gcc flag -fno-exceptions
        Any use of exceptions cause fail to build. I do not know what is the exact errors.
        I think it will not help at all if I catch all exceptions because I do not want to use exceptions mechanism at all.

        K 1 Reply Last reply 10 Jan 2018, 11:18
        0
        • V Offline
          V Offline
          VRonin
          wrote on 8 Jan 2018, 18:12 last edited by
          #4

          From https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_exceptions.html:

          If you might have some code that throws, you shouldn't use -fno-exceptions. If you have some code that uses try or catch, you shouldn't use -fno-exceptions.

          So the answer is no

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          K 1 Reply Last reply 8 Jan 2018, 18:17
          4
          • V VRonin
            8 Jan 2018, 18:12

            From https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_exceptions.html:

            If you might have some code that throws, you shouldn't use -fno-exceptions. If you have some code that uses try or catch, you shouldn't use -fno-exceptions.

            So the answer is no

            K Offline
            K Offline
            Kofr
            wrote on 8 Jan 2018, 18:17 last edited by
            #5

            @VRonin thank you for your answer.

            1 Reply Last reply
            0
            • K Kofr
              8 Jan 2018, 10:56

              I want to include classes to my noexcept project which throw exceptions (I say about cryptopp).
              After that my project can not be built.
              How to leave the project noexcept when continue using cryptopp with exceptions?
              What technics exist to make class noexcept? (hope there is any besides direct deleating throwing code in original classes)

              K Offline
              K Offline
              Konstantin Tokarev
              wrote on 10 Jan 2018, 01:03 last edited by
              #6

              @Kofr You can build part of your project that uses throwing code without -fno-exceptions.

              Or just use different library that doesn't throw, like openssl or gcrypt.

              K 1 Reply Last reply 12 Jan 2018, 13:06
              2
              • K Kofr
                8 Jan 2018, 16:54

                @Paul-Colby thank you for the answer.
                I compile with use qmake CONFIG += exceptions_off.
                This is same as gcc flag -fno-exceptions
                Any use of exceptions cause fail to build. I do not know what is the exact errors.
                I think it will not help at all if I catch all exceptions because I do not want to use exceptions mechanism at all.

                K Offline
                K Offline
                Konstantin Tokarev
                wrote on 10 Jan 2018, 11:18 last edited by
                #7

                @Kofr For example of the exterme case, I'm building QtWebKit with disabled exceptions but one file enables them to catch possible std::bad_alloc from Qt:

                https://github.com/annulen/webkit/blob/qtwebkit-5.212/Source/WebCore/PlatformQt.cmake#L194

                In qmake it's impossible to set flags for one file, so you will need to split exception-enabled code into (static) library

                1 Reply Last reply
                1
                • K Konstantin Tokarev
                  10 Jan 2018, 01:03

                  @Kofr You can build part of your project that uses throwing code without -fno-exceptions.

                  Or just use different library that doesn't throw, like openssl or gcrypt.

                  K Offline
                  K Offline
                  Kofr
                  wrote on 12 Jan 2018, 13:06 last edited by
                  #8

                  @Konstantin-Tokarev I still see the problem. If you build exception throwing code into .lib or .a there is still header which is not noexcept. Is it ok for the compiler to work with such header and lib or the problem is real?

                  K 2 Replies Last reply 12 Jan 2018, 13:30
                  0
                  • K Kofr
                    12 Jan 2018, 13:06

                    @Konstantin-Tokarev I still see the problem. If you build exception throwing code into .lib or .a there is still header which is not noexcept. Is it ok for the compiler to work with such header and lib or the problem is real?

                    K Offline
                    K Offline
                    Konstantin Tokarev
                    wrote on 12 Jan 2018, 13:30 last edited by
                    #9

                    @Kofr Seems like you didn't understand problem yet. You need to separate catching code into the library, not only throwing.

                    So you basically need a wrapper that will call trowing functions and catch all exceptions, then use this wrapper in noexcept code.

                    K 1 Reply Last reply 12 Jan 2018, 15:09
                    2
                    • K Kofr
                      12 Jan 2018, 13:06

                      @Konstantin-Tokarev I still see the problem. If you build exception throwing code into .lib or .a there is still header which is not noexcept. Is it ok for the compiler to work with such header and lib or the problem is real?

                      K Offline
                      K Offline
                      Konstantin Tokarev
                      wrote on 12 Jan 2018, 13:32 last edited by
                      #10

                      (I hope you are not going to ignore errors from cryptographic library)

                      1 Reply Last reply
                      0
                      • K Konstantin Tokarev
                        12 Jan 2018, 13:30

                        @Kofr Seems like you didn't understand problem yet. You need to separate catching code into the library, not only throwing.

                        So you basically need a wrapper that will call trowing functions and catch all exceptions, then use this wrapper in noexcept code.

                        K Offline
                        K Offline
                        Kofr
                        wrote on 12 Jan 2018, 15:09 last edited by
                        #11

                        @Konstantin-Tokarev said in Including Throwing Exceptions classes to NOEXCEPT project:

                        sically need a wrapper that will call trowing functions and catch all exceptions, then use this wrapper in noexcept code.

                        thx, now I got the trick

                        K 1 Reply Last reply 12 Jan 2018, 15:13
                        0
                        • K Kofr
                          12 Jan 2018, 15:09

                          @Konstantin-Tokarev said in Including Throwing Exceptions classes to NOEXCEPT project:

                          sically need a wrapper that will call trowing functions and catch all exceptions, then use this wrapper in noexcept code.

                          thx, now I got the trick

                          K Offline
                          K Offline
                          Konstantin Tokarev
                          wrote on 12 Jan 2018, 15:13 last edited by
                          #12

                          Also, I don't know if this trick works with MSVC, didn't try that yet

                          V 1 Reply Last reply 12 Jan 2018, 16:07
                          0
                          • K Konstantin Tokarev
                            12 Jan 2018, 15:13

                            Also, I don't know if this trick works with MSVC, didn't try that yet

                            V Offline
                            V Offline
                            VRonin
                            wrote on 12 Jan 2018, 16:07 last edited by
                            #13

                            @Konstantin-Tokarev Visual Studio allows per-file compile flags so the trick should be redundant

                            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                            ~Napoleon Bonaparte

                            On a crusade to banish setIndexWidget() from the holy land of Qt

                            K 1 Reply Last reply 12 Jan 2018, 17:39
                            1
                            • V VRonin
                              12 Jan 2018, 16:07

                              @Konstantin-Tokarev Visual Studio allows per-file compile flags so the trick should be redundant

                              K Offline
                              K Offline
                              Konstantin Tokarev
                              wrote on 12 Jan 2018, 17:39 last edited by
                              #14

                              @VRonin I don't doubt that Visual Studio can do this, my poins are

                              • qmake doesn't have native way to set source-specific flags, you need to create your own custom target with all gory details of building C++ file, so it's much easier to move it into library
                              • I don't know if mixing EH flags in the same binary is reliable with MSVC
                              1 Reply Last reply
                              0

                              10/14

                              12 Jan 2018, 13:32

                              • Login

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