except20.c

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

C
51
字号
#include "fail.h"

struct xa { xa(); int x; };
xa::xa() : x(0xaaaa) {
}
struct xb { xb(); int x; };
xb::xb() : x(0xbbbb) {
}
struct xc { xc(); int x; };
xc::xc() : x(0xcccc) {
}

int seq;

void sequence( int x, unsigned line )
{
    if( x != seq ) fail(line);
    ++seq;
}

void test() {
    try {
        throw;
    } catch (xa& a) {
	sequence( 0, __LINE__ );
    } catch (xb& b) {
	sequence( 1, __LINE__ );
    } catch (...) {
	sequence( 2, __LINE__ );
    }
}

int main() {
    try {
        throw xa();
    } catch (...) {
        test();
    }
    try {
        throw xb();
    } catch (...) {
        test();
    }
    try {
        throw xc();
    } catch (...) {
        test();
    }
    _PASS;
}

⌨️ 快捷键说明

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