How do you use noxcept for practical use?

Asked 1 years ago, Updated 1 years ago, 235 views

If you look at the commentary on noexcept, there was an explanation that the function should specify when it does not send an exception.For what purpose is it used in practical use?What purpose do you use in your daily development to achieve in the end?

c++

2022-09-30 21:56

2 Answers

For what practical purposes is it used?

noexceptThe designator is used for two main purposes:

  • Security: Avoid dangerous actions such as sending exceptions from the destructor
  • Processing efficiency: Take advantage of no exception to implement more efficiently

Note that the presence or absence of noexcept is considered part of the external public interface.Given that noexcept specification for a function is a declaration "do not send an exception as an external specification for this function", it should not be given if there is a possibility of sending an exception in the future (which leads to very difficult and disruptive API specification changes).

C++ Core Guideline (same Title) provides some guidelines for using .


2022-09-30 21:56

noexcept is a specification introduced in , so it is a specification introduced in