Just as I can see in cppreference, the classic "throw" declaration lists is now deprecated in C++11. What is the reason of leaving this mechanism and how should I have to specify what exceptions throws a function of mine?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
Only the form without a list throw() is deprecated. Forms without the missing list throw(int, exception&), etc. are not deprecated.
The answer Peter gave does not hit the actual problem of exception specifications for the implementor and user:
The conclusion is that C++ should have just gone the way that Java did it:
Noexcept (since C++11) suffers the same conceptual mistake, since it will also cause run-time termination if the specification is not adhered too, i.e. a method throws that was declared not to. This makes
noexcept
impossible to use for anything serious but the most contained cases (move constructors come to mind).They produce slower and bigger code, because libc++ has to check if any exception propagating out of a function violates it's exception specification and call
std::unexpected
. This is hardly ever useful, and is worse than just documenting the exceptions a function throws yourself.For more detailed reasoning, see: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3051.html