[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to replace throw exceptions in C++11



Hi,

Am 2017-08-25 10:10, schrieb Andreas Tille:
I try to fix #872262 and while I've read that dynamic exception
specifications are deprecated in C++11 I have not found a sensible
replacement for the affected code.

Any hint what to do here?

The main issue with the code are not the exception specifications but
rather that you build with -Werror here. -Werror is great for
developers (to make sure no warnings get ignored when the software is
written), but it's an awful thing to have in distribution packages.
Switch to a new compiler (as has happened here) that suddenly has
additional warnings, and builds just start to fail needlessly.

The patch in the bug report already disables -Werror - and that should
definitely be what you should use to build the package even after those
warnings have gone.

(What is possible is to build a package with specific warnings made to
errors, for example -Werror=format-security, to catch really bad bugs.
But that should be opt-in, not just a generic -Werror "please turn ALL
warnings into errors".)

As for the replacement for affected code (for the long term): C++11 has
noexcept as a replacement for throw() with empty parameter list - so if
you are _really_, _really_, _really_ sure that a function doesn't ever
throw you can specify noexcept after the function name. (If it does
throw anyway, the program will exit.) Please note though that - as with
const - noexcept is part of the function name mangling, so void foo();
and void foo() noexcept; are two separate functions when it comes to
their symbol name - so if you want to keep binary compatibility, adding
noexcept in cases where there are empty throw() specifications might
not be an option. As for exception specifications with explicitly named
exception names, for example throw(std::runtime_error) after a function
name: there's no replacement for that in C++11, just remove those
entirely if you want to be conforming. (They were useless in previous
C++ versions anyway, to my knowledge no compiler ever did anything with
those specifications.)

Regards,
Christian


Reply to: