except04.c

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

C
62
字号
#include "fail.h"
// Revisions:
//
// 93/11/01 -- J.W.Welch        -- removed test for throw of zero (standard
//                                 says only exact member-ptr conversions are
//                                 allowed)


#include <stdio.h>
#include <stdlib.h>

struct S {
    int a;
    int b;
    int c;
};

S x = { 6, 28, 1 };
S *p = &x;

int main()
{
    for( int i = 1; i < 3; ++i ) {
        try {
            switch( i ) {
            case 0:
                throw 0;
                break;
            case 1:
                throw &x;
                break;
            case 2:
                throw p;
                break;
            default:
		fail(__LINE__);
            }
        } catch( S * &xx ) {
            switch( i ) {
            case 0:
                if( xx ) {
		    fail(__LINE__);
                }
                break;
            case 1:
                if( xx->b != 28 ) {
		    fail(__LINE__);
                }
                break;
            case 2:
                if( xx->c != 1 ) {
		    fail(__LINE__);
                }
                break;
            }
        } catch( ... ) {
	    fail(__LINE__);
        }
    }
    _PASS;
}

⌨️ 快捷键说明

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