# warning: dynamic exception specifications are deprecated in C++11

**URL:** https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470
**Category:** Engineering
**Created:** [November 30, 2017, 11:03am UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470 "2017-11-30T11:03:40Z")
**Posts on this page:** 2
**Page:** 3

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [December 7, 2017, 10:57pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/41 "2017-12-07T22:57:51Z")

</div>

I don’t understand either how the compiler can suffer a performance hit when using it, but I don’t try to grasp the complexities of compilers, maybe related to the existing zero-cost abstraction for exceptions (they are free in terms of performance except when they actually throw) so +1 for benchmarking.

But even ignoring this performance issue, and after reading for a while about the topic, I don’t think flagging everything as `noexcept` is a good idea.  
Exceptions are about handling the recovery, `noexcept` is nothing else than saying, don’t try to recover from whatever exceptional behavior that might occur in this function. But most of the cases… you don’t care if the compiler tried to unwind everything and then terminate because uncaught exception, or directly terminate without the unwinding (when `noexcept` is specified).

The big gain then is not in machine code, it is in the standards established in algorithms, and those standards say that if you have a `noexcept move assignment`, and/or a `noexcept swap` they will be used instead of copying, with big algorithmic optimizations as @LucH pointed out.  
These algorithmic optimizations require noexcept [in:](https://stackoverflow.com/a/27649221/3386303)

- move constructor and assignment.
- swap
- memory deallocators
- destructors (noexcept by default since c++11)

It is hard to think about exceptions, so I agree that it is good idea to limit the use to the cases where it really matters. Of course, I am talking generally, there must be low-level functions that are worth to specify as `noexcept` as well for development reasons.

---

<div class="post-metadata">

### Author: ![LucH](https://discourse.itk.org/letter_avatar_proxy/v4/letter/l/c5a1d2/32.png) [@LucH](https://discourse.itk.org/u/LucH)
#### Post date: [December 8, 2017, 10:25am UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/42 "2017-12-08T10:25:00Z")

</div>

The following presentation by Jason turner is quite instructive on what the compiler could do with `noexcept` annotations: [https://www.youtube.com/watch?v=OkgvqjJzH\_Y](https://www.youtube.com/watch?v=OkgvqjJzH_Y)

Unfortunately, this doesn’t cover MSVC nor x86.

Anyway, this is the reason that makes me think that at least non-inlined low level functions called by move operations, swap, and destructors also need to be declared `noexcept`.

[Previous page](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470.md?page=2)
