How now correctly to specify that function throws out exceptions? Write throw(...) or list possible exceptions or write nothing at all?

And another question: what is indicated in brackets after noexcept ?

    1 answer 1

    If the function throws an exception, then write nothing. (Or you can equivalently write noexcept(false) ).

    What is indicated in brackets noexcept depends on what noexcept you are talking about. There is a noexcept operator , and there is a noexcept .

    • The noexcept operator checks the noexcept status of an expression. This is the compile time operator. The operand is an expression whose noexcept status you want to know. The compiled operator will return true or false .

    • The noexcept contrary assigns the noexcept-status of the function. It declares whether a given function is noexcept or not. Just noexcept says the function is noexcept . And in the variant with the Boolean operand, the noexcept-status is determined by the value of the Boolean expression.

    For example, the following example uses both the noexcept operator and the noexcept specifier noexcept

     void bar() noexcept(noexcept(foo())); ^ ^ | | | оператор спецификатор 

    The bar() function will result in the same noexcept-status as the foo() function.

    • And how then to be with the specification of exceptions through throw. Why is it marked obsolete ? In my opinion, a convenient mechanism (in order to self-document). I would have worked at the compilation stage (a la as in java) - he wouldn’t have the price ... - mymedia
    • one
      @mymedia: “Official” reasons for cancellation: checking at run-time, in case of violation, recovery is impossible, high overhead, inapplicability in generic code where specification of exceptions of the called code cannot be predicted at all ( open-std.org/jtc1/sc22 /wg21/docs/papers/2010/n3051.html ). Herb Sutter can be discussed in more detail in gotw.ca/publications/mill22.htm . This is an extensive topic, in the comments can not be raspeshesh detail. - AnT