CPlusPlusThings/practical_exercises/10_day_practice/day9/异常例子/5.cpp
Light-City a4d828bb4c update
2020-04-06 00:57:02 +08:00

20 lines
436 B
C++

//Eg10-5.cpp
#include<iostream>
using namespace std;
void handler(int n)throw(int,char,double){
if(n==1) throw n;
if(n==2) throw 'x';
if(n==3) throw 1.1;
}
int main(){
cout<<"Before handler..."<<endl;
try{
handler(1);
}
catch(int i){ cout<<"catch an integer..."<<endl;}
catch(char c){cout<<"catch an char..."<<endl;}
catch(double d){cout<<"catch an double..."<<endl;}
system("pause");
}