f1506.cpp
来自「《C++程序设计教程(第二版)》源代码 源代码中包括运行所需的数据文件,它的格」· C++ 代码 · 共 40 行
CPP
40 行
//=====================================
// f1506.cpp
// 异常匹配
//=====================================
#include<iostream>
using namespace std;
//-------------------------------------
class A{};
class B{};
//-------------------------------------
int main(){
try{
int j=0;
double d=2.3;
char str[20]="Hello";
cout<<"Please input a exception number: ";
int a; cin>>a;
switch(a){
case 1: throw d;
case 2: throw j;
case 3: throw str;
case 4: throw A();
case 5: throw B();
default: cout<<"No throws here.\n";
}
}catch(int){
cout<<"int exception.\n";
}catch(double){
cout<<"double exception.\n";
}catch(char*){
cout<<"char* exception.\n";
}catch(A){
cout<<"class A exception.\n";
}catch(B){
cout<<"class B exception.\n";
}
cout<<"That's ok.\n";
}//====================================
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?