//异常处理关键字try,throw,catch的使用
#include <iostream.h >
class exception
{
public:
void func()
{
try//try代码块被称为监视块
{
throw 1;//throw发送异常信息
}
catch(int a)//该参数接收整形错误信息,(...)将接收任何类型的错误信息
{
cout << "捕获的异常号码:" << a << endl;
return;
}
cout <<"没有检测到任何异常!" << endl;
return;
}
};
int main()
{
exception ex;
ex.func ();
return 0;
}
#include <iostream.h >
class exception
{
public:
void func()
{
try//try代码块被称为监视块
{
throw 1;//throw发送异常信息
}
catch(int a)//该参数接收整形错误信息,(...)将接收任何类型的错误信息
{
cout << "捕获的异常号码:" << a << endl;
return;
}
cout <<"没有检测到任何异常!" << endl;
return;
}
};
int main()
{
exception ex;
ex.func ();
return 0;
}