# 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:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [November 30, 2017, 11:03am UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/1 "2017-11-30T11:03:40Z")

</div>

Hi,  
I get this warning with gcc 7.2.1, see  
[http://my.cdash.org/viewBuildError.php?type=1&buildid=1330451](http://my.cdash.org/viewBuildError.php?type=1&buildid=1330451)  
I don’t understand the code generating it so I don’t know how to fix it. Any suggestion?  
Simon

---

<div class="post-metadata">

### Author: ![tim-evain](https://discourse.itk.org/user_avatar/discourse.itk.org/tim-evain/32/220_2.png) [@tim-evain](https://discourse.itk.org/u/tim-evain)
#### Post date: [November 30, 2017, 11:46am UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/2 "2017-11-30T11:46:11Z")

</div>

Hi Simon,

From what I’m seeing, the warnings are generated by various files from ITK.  
This comes from the fact that [exception specification](http://en.cppreference.com/w/cpp/language/except_spec) is deprecated since C++11 (see [this post](https://stackoverflow.com/questions/13841559/deprecated-throw-list-in-c11) for some discussion about it) so writing function like:  
virtual void MultiThreadingInitialize(void) **throw ( ExceptionObject )**;  
will generate warnings.

HTH,

Tim

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [November 30, 2017, 1:55pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/3 "2017-11-30T13:55:12Z")

</div>

Thanks. I had seen that but I do not really understand why would someone retrict the exceptions that a function can throw. My suggestion is to just remove all dynamic exception specifications from the ITK code rather than having yet another compiler specific variable. Would someone from Kitware agree with that change?

---

<div class="post-metadata">

### Author: ![fbudin](https://discourse.itk.org/user_avatar/discourse.itk.org/fbudin/32/14_2.png) [@fbudin](https://discourse.itk.org/u/fbudin)
#### Post date: [November 30, 2017, 2:29pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/4 "2017-11-30T14:29:27Z")

</div>

@simon.rit : In general ITK is really conservative when it comes to modifying compilation options as it can break things badly. In this case, I don’t think there is any reason to worry too much about it since it has even been removed from the C++ standard in C++17, so I think we could go either way. If a macro is added, it should check that `__cplusplus >= 201703L`. `Clang tidy` apparently has a checker to replace this call, so it shouldn’t be too difficult either way ([see here](https://reviews.llvm.org/D18575)). Could you submit a patch on gerrit to correct that issue? There is no `request build: cpp17` command set up yet to request c++ 17 builds on the dashboards, but I will look into adding this.

---

<div class="post-metadata">

### Author: ![fbudin](https://discourse.itk.org/user_avatar/discourse.itk.org/fbudin/32/14_2.png) [@fbudin](https://discourse.itk.org/u/fbudin)
#### Post date: [November 30, 2017, 8:52pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/5 "2017-11-30T20:52:13Z")

</div>

@simon.rit: I added a set of dashboards (Linux, Windows, MacOSX) that can compile ITK with C++17. To request these builds, on gerrit you need to type `request build: cpp17` ([see here](https://itk.org/Wiki/ITK/Git/Develop#Test_a_Topic)). I am in the process of testing that it works, and I will update this topic when testing is done.

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [November 30, 2017, 8:55pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/6 "2017-11-30T20:55:47Z")

</div>

@fbudin: ok great, thanks. I’ll submit a patch tomorrow, I won’t be able to do it tonight.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [November 30, 2017, 8:57pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/7 "2017-11-30T20:57:36Z")

</div>

I believe these exception type specification should be removed. If a method throws an exception which is not specified, then the program is suppose to immediately about. This would not be good behavior.

However, the no throw specification is still quite useful when you want to ensure that code is exception safe or writing a class destructor.

---

<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 1, 2017, 12:59am UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/8 "2017-12-01T00:59:56Z")

</div>

Yeah, +1 to remove dynamic exceptions. Also it doesn’t add much value specifying to throw a generic `ExceptionObject`. I like the text in the standard referenced [there](https://stackoverflow.com/questions/13841559/deprecated-throw-list-in-c11), either the function might throw any exception (the default) or it doesn’t. In the later case, we tag the function with `noexcept` (since c++11) or the empty `throw()`.

---

<div class="post-metadata">

### Author: ![fbudin](https://discourse.itk.org/user_avatar/discourse.itk.org/fbudin/32/14_2.png) [@fbudin](https://discourse.itk.org/u/fbudin)
#### Post date: [December 1, 2017, 1:00am UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/9 "2017-12-01T01:00:31Z")

</div>

Just as an update, requesting a build with `request build: cpp17` worked for the one patch I tried it on.

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [December 1, 2017, 7:46pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/10 "2017-12-01T19:46:16Z")

</div>

Ok, I submitted it a patch:  
[http://review.source.kitware.com/#/c/22844/](http://review.source.kitware.com/#/c/22844/)  
Let me know if I didn’t do the cpp17 build request correctly

---

<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 1, 2017, 9:59pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/11 "2017-12-01T21:59:51Z")

</div>

Thanks @simon.rit! I have commented in gerrit, proposing to change the name of the macro, from `ITK_NOEXCEPT_OR_THROW` to just `ITK_NOEXCEPT`. The macro was there before your patch, but seems like a good opportunity to improve it.

The or\_throw bit is confusing for the reader, is the function noexcept or throwing? Clearer would be `ITK_NOEXCEPT_OR_EMPTY_THROW` but it is not pleasant to read at all. I think the macro should state the purpose, not the implementation details of the language.

---

<div class="post-metadata">

### Author: ![fbudin](https://discourse.itk.org/user_avatar/discourse.itk.org/fbudin/32/14_2.png) [@fbudin](https://discourse.itk.org/u/fbudin)
#### Post date: [December 4, 2017, 2:42pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/12 "2017-12-04T14:42:06Z")

</div>

Actually, `ITK_NOEXCEPT` is already defined in `itk_compiler_detection.h` whereas `ITK_NOEXCEPT_OR_EMPTY_THROW` is defined in `itkMacro.h`. @blowekamp @matt.mccormick : Any historical knowledge about why this seem to be defined twice, under different names?

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [December 4, 2017, 3:12pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/13 "2017-12-04T15:12:11Z")

</div>

The name for the macro ITK\_NOEXCEPT\_OR\_THROW must not change. Supporting multiple legacy names is going to be significantly more confusing than the current name you don’t get (yet).

You can see where the naming came from by looking at the code:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/include/itkMacro.h#L234-L238>

This macro produces the proper function specification for C++03, and C++11. I’d blame C++03 for the convention of having to use “throw()” to specify no exception.

ITK\_NOEXCEPT does not provide a C++03 implementation:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/include/itk_compiler_detection.h#L266-L272>

ITK\_NOEXCEPT follows CMake’s compiler detection module, while ITK\_NOEXCEPT\_OR\_THROW was defined for ITK’s compatibility needs.

---

<div class="post-metadata">

### Author: ![fbudin](https://discourse.itk.org/user_avatar/discourse.itk.org/fbudin/32/14_2.png) [@fbudin](https://discourse.itk.org/u/fbudin)
#### Post date: [December 4, 2017, 3:35pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/14 "2017-12-04T15:35:23Z")

</div>

@blowekamp Don’t you think having two macros that do basically the same thing is confusing? Which one should an ITK developer use? Or in which case should one or the other be used? There is no documentation in the source code or in the Software Guide for these macros.  
Looking at where `ITK_NOEXCEPT_OR_THROW` is used, it seems that it is used in files handling exceptions (e.g. `itkExceptionObject.cxx`).

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [December 4, 2017, 3:52pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/15 "2017-12-04T15:52:14Z")

</div>

+1 for making exclusive use of `ITK_NOEXCEPT` and marking `ITK_NOEXCEPT_OR_THROW` as deprecated. We cannot remove `ITK_NOEXCEPT_OR_THROW` altogether because of backwards compatibility.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [December 4, 2017, 4:11pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/16 "2017-12-04T16:11:56Z")

</div>

I do prefer the naming of `ITK_NOEXCEPT`, but the behavior of `ITK_NOEXCEPT_OR_THROW` is needed for C++03 compatibility.

Its not known to me if every case where there is an `ITK_NOEXPECT`a `throw()` would work in C++03. Likely a C++11 enthusiast added the ITK\_NOEXPECT in ITK code to address C++11 warnings so the code difference was probably unintentional.

The source of `ITK_NOEXCEPT` is in `itk_compiler_detection.h` which is generated by CMake’s [WriteCompilerDetectionHeader](https://cmake.org/cmake/help/v3.6/module/WriteCompilerDetectionHeader.html?highlight=noexcept) module, then committed to ITK. So modification of that macro or file is problematic.

I believe there other duplications of macros in `itkMacro` and in itk\_compiler\_detection.h. In general I think we should prefer what is in `itkMacro` over itk\_compiler\_detection. What is in itkMacro we are able to customize and update to ITK’s needs vs what is in the germinated code. I would almost say what in in itk\_compiler\_detection should be an implementation detail, and the public interface should be in itkMacro.h.

---

<div class="post-metadata">

### Author: ![fbudin](https://discourse.itk.org/user_avatar/discourse.itk.org/fbudin/32/14_2.png) [@fbudin](https://discourse.itk.org/u/fbudin)
#### Post date: [December 4, 2017, 4:59pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/17 "2017-12-04T16:59:04Z")

</div>

Thanks! I didn’t know how `itk_compiler_detection.h` was generated. @brad.king : Is there a way when calling `WriteCompilerDetectionHeader` in `CMake` to detect if `Dynamic exception specifications have been removed from cpp17` (i.e. `throw(typeid, typeid, ...)` is deprecated or removed)?

---

<div class="post-metadata">

### Author: ![seanm](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/a88e4f/32.png) [@seanm](https://discourse.itk.org/u/seanm)
#### Post date: [December 4, 2017, 5:46pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/18 "2017-12-04T17:46:51Z")

</div>

Not to hijack the thread, but… why bother supporting pre=C++11 at all at this point in time? For comparison: VTK, CMake, and GDCM all require C++11 now.

Sean

---

<div class="post-metadata">

### Author: ![fbudin](https://discourse.itk.org/user_avatar/discourse.itk.org/fbudin/32/14_2.png) [@fbudin](https://discourse.itk.org/u/fbudin)
#### Post date: [December 4, 2017, 5:58pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/19 "2017-12-04T17:58:18Z")

</div>

@seanm One good reason for us to support pre-c++11 features is that on Windows, we support Python2.7, and it requires ITK to be built with Visual Studio 2008.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [December 4, 2017, 6:04pm UTC](https://discourse.itk.org/t/warning-dynamic-exception-specifications-are-deprecated-in-c-11/470/20 "2017-12-04T18:04:42Z")

</div>

> [@blowekamp](#):
>
> I do prefer the naming of ITK\_NOEXCEPT, but the behavior of ITK\_NOEXCEPT\_OR\_THROW is needed for C++03 compatibility.

The point was that we could just remove the `throw()`.

Recalling a recent talk by a Visual Studio backend developer and confirmed [in this post](https://akrzemi1.wordpress.com/2011/06/10/using-noexcept/), `noexcept` currently actually results in decreased performance due to implementation details, so we could remove the macros from where they are applied altogether.

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