throw()(or noexceptin C ++ 11) is useful for two reasons:
- This allows the compiler to be more aggressive in its optimizations.
- It tells function users that they can use this function in their own non-throwing functions.
. , operator= non-throwing swap().
, . .
, noexcept , , . , (, VS ), , - . :
void f() noexcept
{
a();
b();
}
a() b() , , b() a(), , .
EDIT: : ?
, . :
class C
{
C* CreateInstance()
{
return new C();
}
}
new std::bad_alloc, CreateInstance() . try-catch, , try, ? :
C* CreateInstance()
{
try
{
return new C();
}
catch (...)
{
return null;
}
}
, , CreateInstance() null? , , . , std::bad_alloc , , .
: , . - .