try catch
原文链接:https://www.dotcpp.com/course/84
语法结构:
try
{
//正常程序执行语句
throw (异常类型表达式);
}
catch(异常类型1)
{
//异常处理代码
}
catch(异常类型2)
{
//异常处理代码
}
catch(异常类型3)
{
//异常处理代码
}
//后续代码
实例:
#include <iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
try
{
if(b==0)
throw "error! b<0";
}
catch(const char *str)
{
cout<<str<<endl;
}
catch(int)
{
cout<<"throw int "<<endl;
}
return 0;
}
标签:try,int,代码,c++,语法,徒步,catch,异常,throw
From: https://www.cnblogs.com/fusio/p/17283840.html