📄 catch.cpp
字号:
#include <iostream>#include <stdlib.h>using namespace std;void foo() { int i, j; i = 14; j = 15; throw i;}void call_foo() { int k; k = 12; foo(); throw ("This is from call_foo");}void call_foo2() { double x = 1.3; unsigned m = 1234; throw (x); throw m;}int main() { try { call_foo(); call_foo2(); } catch(const char* message) { /* Is const necessary here? */ cerr << message << endl; exit(1); } catch(int &n) { cout << "caught int " << n << endl; } catch(double& d) { /* abstract parameter */ cout << "caught a double:" << d << endl; } catch( ... ) { /* default action to be taken */ cerr << "ellipsis catch" << endl; abort(); }}/*OUT# with the first throw commented outsrc/generic> g++ catch.cppsrc/generic> ./a.outThis is from call_foosrc/generic> # with the first two throws commented outsrc/generic> g++ catch.cppsrc/generic> ./a.outcaught a doublesrc/generic> # with the first three throws commented outsrc/generic> g++ catch.cppsrc/generic> ./a.outellipsis catchAbortedsrc/generic> # with all the throws enabledsrc/generic> g++ catch.cppsrc/generic> ./a.outcaught int 14src/generic> */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -