: -
コード1: - ここに
#include <iostream>
using namespace std;
void foo() noexcept // see the noexcept specifier
{
throw 42;
}
int main()
{
try
{
foo();
}
catch(...)
{
cerr<<"exception caught\n";
}
return 0;
}
出力は次のようになります - 私は削除した場合
terminate called after throwing an instance of 'int'
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
noexcept
: -
コード2 -
#include <iostream>
using namespace std;
void foo() // noexcept is eliminated
{
throw 42;
}
int main()
{
try
{
foo();
}
catch(...)
{
cerr<<"exception caught\n";
}
return 0;
}
出力は次のようになります -
exception caught
foo
が故にterminate
が呼び出された、noexcept
として署名されたので。彼らは、これらの機能がnoexcept(false)
である場合にはnoexcept(false)
ある機能を呼び出すために必要とされない限り、
Inheriting constructors
とimplicitly-declared default constructors, copy constructors, move constructors, destructors, copy-assignment operators, move-assignment operators
は、すべてデフォルトでnoexcept(true)
です。
また、ラインが好きで書くことができます: - foo
がexception
かスローされます場合
cout << boolalpha << noexcept(foo); // here noexcept acts as
// an operator instead of a specifier
上記の行をチェックします。それがスローされた場合、戻り値はtrue
else false
になります。
あなたはこの中でこれらの詳細を確認することができます - [?私は本当にnoexcept使用する必要があります]の>http://scottmeyers.blogspot.dk/2014/03/declare-functions-noexcept-whenever.html
可能な複製(http://stackoverflow.com/questions/10787766/when-should-i-really -use-noexcept) –
便利な情報はこちら[こちら](http://stackoverflow.com/questions/26079903/noexcept-stack-unwinding-and-performance)、特に[この回答](http:// stackoverflow .com/a/26080332/1969455)。 –