noexcept Operator in C++

In C++, the noexcept operator is a compile-time operator that is used to check whether an expression will throw an exception. It checks the exception specification of the functions, but functions are not called or evaluated at runtime. The compiler checks the results based on the function declaration.

Also, when creating a function template, we can use noexcept it to specify whether the function might throw exceptions or not for some specific data types.

Note: The noexcept operator does not actually evaluate the expression passed in the parameters. It simply checks whether the given expression will throw an exception or not.

Syntax of noexcept Operator

noexcept(expression)

Parameters

expression: It is the expression we want to evaluate.

Return Value

The function does not return any value. The result is true if the expression is guaranteed to not throw exceptions, otherwise, the result is false.

noexcept Operator in C++ 11

Exception handling is an important concept in C++. Keywords like ‘try’, ‘catch’, and ‘throw’ are often associated with exception handling. Although these keywords are very powerful on their own we need another more efficient method to operate on them. Hence, noexcept operator was introduced in C++ 11.

Similar Reads

noexcept Operator in C++

In C++, the noexcept operator is a compile-time operator that is used to check whether an expression will throw an exception. It checks the exception specification of the functions, but functions are not called or evaluated at runtime. The compiler checks the results based on the function declaration....

Example of noexcept Operator

Example 1:...