异常处理的预习
#include<iostream>
using namespace std;
void f3(int x) {
switch(x) {
case 1:throw 3.4;
case 2:throw 2.5f;
case 3:throw 1;
}
cout << "end of F3" << endl;
}
void f2(int x) {
try {
f3(x);
}
catch(int) {cout << "int error from f2" << endl;}
catch(float) {cout << "float error from f2" << endl;}
cout << "end of f2" << endl;
}
void f1(int x) {
try {f2(x);}
catch (int) {
cout << "int error from f1\n";
}
catch (float) {
cout << "float error from f1\n";
}
catch (double) {
cout << "double error from f1\n";
}
cout << "end of f1" << endl;
}
int main() {
for (int i = 1; i < 4; i++)
f1(i);
cout << "end of main" << endl;
return 0;
}
函数调用顺序:main ====> f1 =====> f2 =====> f3