except30.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 54 行

C
54
字号
#include "fail.h"

int locks;

struct L {
    L() {
	++locks;
    }
    ~L() {
	--locks;
    }
};

void foo2() {
    L lock3;
    throw 0;
}

void foo() {
    L lock2;
    foo2();
}

int caught;

int main()
{
    try {
	L lock1;
	foo();
    } catch( int x ) {
	if( x != 0 ) fail(__LINE__);
	++caught;
    } catch( ... ) {
	fail(__LINE__);
    }
    return( errors != 0 );
}

int exit_in_progress;

struct D {
    ~D() {
	if( locks != 0 ) fail(__LINE__);
	if( !caught ) fail(__LINE__);
	if( ! exit_in_progress ) {
	    ++exit_in_progress;
	    _PASS_EXIT;
	}
    }
};

D __dummy;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?