C++ 为什么这个可以抛出?
C++ Why can this throw?
我创建了一个小例外 class。我想制作一个不抛出的构造函数,但出于某种原因,编译器告诉我构造函数可能会抛出,尽管 "catch all" 处理程序:
invalid_csv::invalid_csv( size_t r, size_t c, const char * msg ) throw()
try :
std::runtime_error( msg ),
row( r ),
col( c ),
m_init_ok( true )
{
}
catch( ... )
{
m_init_ok = false;
}
.
warning C4297: 'csvrw::invalid_csv::invalid_csv': function assumed not to throw an exception but does
为什么会这样?谢谢。
To resolve C4297, do not attempt to throw exceptions in functions that are declared __declspec(nothrow), noexcept(true) or throw(). Alternatively, remove the noexcept, throw(), or __declspec(nothrow) specification.
A so-called function-try-block like this cannot prevent that an exception will get outside. Consider that the object is never fully constructed since the constructor can't finish execution. The catch-block has to throw something else or the current exception will be rethrown
阅读this answer
我创建了一个小例外 class。我想制作一个不抛出的构造函数,但出于某种原因,编译器告诉我构造函数可能会抛出,尽管 "catch all" 处理程序:
invalid_csv::invalid_csv( size_t r, size_t c, const char * msg ) throw()
try :
std::runtime_error( msg ),
row( r ),
col( c ),
m_init_ok( true )
{
}
catch( ... )
{
m_init_ok = false;
}
.
warning C4297: 'csvrw::invalid_csv::invalid_csv': function assumed not to throw an exception but does
为什么会这样?谢谢。
To resolve C4297, do not attempt to throw exceptions in functions that are declared __declspec(nothrow), noexcept(true) or throw(). Alternatively, remove the noexcept, throw(), or __declspec(nothrow) specification.
A so-called function-try-block like this cannot prevent that an exception will get outside. Consider that the object is never fully constructed since the constructor can't finish execution. The catch-block has to throw something else or the current exception will be rethrown
阅读this answer