版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_23859701/article/details/81452630
//异常语法
int divide(int a, int b)
{
if(y==0)
{
throw y;
}
return x/y;
}
int main()
{
//试着去捕获异常
try{
divide(10,0);
}
catch(int e)//异常根据类型匹配
{
cout<<"除数为0"<<e<<endl;
}
}
//如果异常抛到顶层,还没有处理,程序就会挂掉。
//c++异常机制 跨函数
//c++异常必处理