//Rethrowing 实质还是异常的嵌套
#include<iostream>
using namespace std;int main()
{
try
{
try
{
exception e("It's my error");
cout << "I'm trying" << endl;
throw e;
}
catch (exception &e)
{
cout << "I'm First Exception but I can't handle it" << endl;
//可改变异常的状态//正是c++ primer 中所提及的
throw;
}
}
catch (exception &e)
{
cout << "I'm Second Exception if you can't handle it let me handle it" << endl;
}
system("pause");
return 0;
}
本文通过一个具体的 C++ 程序示例,展示了如何使用异常嵌套进行错误处理。通过 rethrowing 技术,演示了异常如何在不同的 catch 块间传递并最终被处理。
1246

被折叠的 条评论
为什么被折叠?



