//professional C++ 4th edition p 307
#include
#include
#include
#include
void funcOne();
void funcTwo();
int main()
{
try {
funcOne();
} catch (const std::exception& e ) {
std::cerr << “Exception caught!” << std::endl; // 执行此行!!
return 1;
}
return 0;
}
//void funcOne()
//{
// std::string str1; //p308
// auto str2 = std::make_uniquestd::string(“hello”);
// funcTwo();
//}
void funcOne(){
std::string str1;
std::string* str2 = new std::string();
try{
funcTwo();
} catch(…) {
delete str2;
throw;
}
delete str2;
}
void funcTwo()
{
std::ifstream fileStream;
fileStream.open(“filename”);
throw std::exception(); // 抛出异常, 直接跳到 main 中对应的位置
fileStream.close(); /