What is the keyword noexcept for and when to use it?

Asked

Viewed 73 times

2

What does the keyword noexcept in C++ and in what situation it should be used?

1 answer

2


Two forms:

Specification attribute

Indicates that the function can not launch an exception, which allows a series of optimizations and the compiler better understand the semantics. After that put can not take, is part of the contract. use it whenever possible. In fact until a new form of exception comes, in C++20 or C++23, avoid exceptions.

In C++14 it was a little different, but do not consider this form, prefer the C++17.

See more on documentation.

Operator

Used essentially for metaprogramming/reflection enabling selections and specializations than compiling as to what to find. Something much more advanced. It is a way to query during the build if the function can not launch exception.

See more on documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.