//异常处理
//writed by swords 2005/3/15
#include<iostream.h>
void main()
{
cout<<"start"<<endl;
try
{
cout<<"inside try block."<<endl;
throw 200;
cout<<"this will not execute.";
}
catch(int i)
{
cout<<"catch an exeception--value is: "<<i<<endl;
}
cout<<"end!";
}
此博客展示了一段C++异常处理代码。代码中,在`try`块里抛出一个整数异常,`catch`块捕获该异常并输出异常值。通过此示例可了解C++中异常处理的基本实现方式。
2048

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



