except24.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 66 行
C
66 行
// PT166095
#include "fail.h"
class xErr {};
int ctored;
struct CD {
CD();
CD(CD const & );
~CD();
void throwException();
int sig;
};
CD::CD() : sig(++ctored) {
//printf("%p %d -- constructor\n", this, sig);
}
CD::CD(CD const &s) : sig(++ctored) {
//printf("%p %d -- copy constructor\n", this, sig);
}
CD::~CD() {
//printf("%p %d -- destructor\n", this, sig);
if( sig < 0 ) fail(__LINE__);
sig = -1;
}
void CD::throwException() {
throw xErr();
}
class X {
public:
X(int i);
~X() {};
private:
int _1;
int _2;
};
X::X(int i) : _1(i), _2(0){
return;
};
void test() {
CD oTest1;
X oX(5);
try {
//printf("-------In try\n");
oTest1.throwException();
} catch(xErr) {
//printf("-------In catch\n");
};
//printf("-------Leaving main\n");
return;
};
int main() {
test();
_PASS;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?