直接上代码:
#include<iostream>
#include<exception>
using namespace std;
int main(){
int x = 10;
int y = 0;
try{
if(y==0)
throw "分母为0!";
cout<<x/y<<endl;
}
catch(char const *s){
cout<<s<<endl;
}
return 0;
}
运行结果如下:
直接上代码:
#include<iostream>
#include<exception>
using namespace std;
int main(){
int x = 10;
int y = 0;
try{
if(y==0)
throw "分母为0!";
cout<<x/y<<endl;
}
catch(char const *s){
cout<<s<<endl;
}
return 0;
}
运行结果如下: