当我声明condition_variable
时,它可能会抛出std::system_error
。可以声明POD类型抛出异常吗?
但是当我声明POD类型时(如int
,double
或float
)怎么样?
像下面的代码:
int main()
{
//do something
int i; //will here throw exception?
}
如果声明一个POD类型可能会抛出异常,我怎么保证
void test() noexcept
{
//do something
int i;
}
是noexcept
?
你问有没有办法通过声明一个变量来抛出异常? – AustinWBryan
是的。这就是我的意思。 – Caesar
声明POD(普通旧数据:'int'等)类型不会抛出异常;但是,任何其他构造函数_may_都会抛出异常。检查文档。你可以看到['std :: condition_variable'](http://en.cppreference.com/w/cpp/thread/condition_variable/condition_variable)的构造函数可以抛出异常。 – Tas