//流程:
//try---->throw -----> catch()
//打印2222222!
//流程Div->thow b->catch(int)
#include <iostream>
using namespace std;
int Div(int a, int b)
{
if(b == 0)
{
throw b;
}
cout<<"OK"<<endl;
return a/b;
}
void main()
{
int a,b;
a = 1;
b = 0;
try
{
Div(a,b);
}
catch(int)
{
cout<<"2222222!"<<endl;
}
catch(...)
{
cout<<"11111111110!"<<endl;
}
}
//打印1111111111!
//流程Div->catch(...)
#include <iostream>
using namespace std;
int Div(int a, int b)
{
cout<<"OK"<<endl;
return a/b;
}
void main()
{
int a,b;
a = 1;
b = 0;
try
{
Div(a,b);
}
catch(...)
{
cout<<"2222222!"<<endl;
}
catch(...)
{
cout<<"1111111111!"<<endl;
}
}
C++之try和catch入门
最新推荐文章于 2023-12-15 21:49:49 发布