mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-05-11 18:38:17 +08:00
support bazel complie this project and format code.
This commit is contained in:
24
practical_exercises/10_day_practice/day9/exception/7.cpp
Normal file
24
practical_exercises/10_day_practice/day9/exception/7.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// Eg10-7.cpp
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
//内部再次throw异常的时候,函数不要带throw()
|
||||
void Errhandler(int n) {
|
||||
try {
|
||||
if (n == 1)
|
||||
throw n;
|
||||
cout << "all is ok..." << endl;
|
||||
} catch (int n) {
|
||||
cout << "catch an int exception inside..." << n << endl;
|
||||
throw n; //再次抛出本catch捕获的异常
|
||||
}
|
||||
}
|
||||
int main() {
|
||||
try {
|
||||
Errhandler(1);
|
||||
} catch (int x) {
|
||||
cout << "catch int an exception in main..." << x << endl;
|
||||
}
|
||||
cout << "....End..." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user