Including Throwing Exceptions classes to NOEXCEPT project
-
wrote on 8 Jan 2018, 10:56 last edited by
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) -
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)wrote on 8 Jan 2018, 11:20 last edited byHi @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.
-
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.
wrote on 8 Jan 2018, 16:54 last edited by@Paul-Colby thank you for the answer.
I compile with useqmake
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. -
wrote on 8 Jan 2018, 18:12 last edited by
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
-
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
-
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)wrote on 10 Jan 2018, 01:03 last edited by@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.
-
@Paul-Colby thank you for the answer.
I compile with useqmake
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.wrote on 10 Jan 2018, 11:18 last edited by@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
-
@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.
wrote on 12 Jan 2018, 13:06 last edited by@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?
-
@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?
wrote on 12 Jan 2018, 13:30 last edited by@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.
-
@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?
wrote on 12 Jan 2018, 13:32 last edited by(I hope you are not going to ignore errors from cryptographic library)
-
@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.
wrote on 12 Jan 2018, 15:09 last edited by@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
-
@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
wrote on 12 Jan 2018, 15:13 last edited byAlso, I don't know if this trick works with MSVC, didn't try that yet
-
Also, I don't know if this trick works with MSVC, didn't try that yet
wrote on 12 Jan 2018, 16:07 last edited by@Konstantin-Tokarev Visual Studio allows per-file compile flags so the trick should be redundant
-
@Konstantin-Tokarev Visual Studio allows per-file compile flags so the trick should be redundant
wrote on 12 Jan 2018, 17:39 last edited by@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
9/14