这可能是一个微不足道的问题 - 但它对我来说并不明显,所以我需要一些确认。假设我有一个try-catch块的功能:C++ try-catch异常处理约定
int function some_crap() {
some_type b;
int a = 10;
try {
a = boost::numeric_cast<int>(b);
}
catch(boost::bad_numeric_cast& e) {
std::cout << e.what() << std::endl;
return a;
}
catch(...) {
//-Handle other unknown exceptions
return a;
}
return a;
}
IIRC,我需要把return a
语句在每个catch
块的,对不对?同样在catch
的每个块中,a
的值将分别为10
,对不对?
感谢您的时间&兴趣。 --T
你可以把一个'返回;在你的函数 –
感谢@Basie的尽头'声明。所以你说这个计划将会在catch块之外回归?这是我不确定的部分。 –
处理未知的例外是不可能的。你可以忽略它们,但那不是真正的“处理”。 – Casey