except37.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 74 行
C
74 行
#include "fail.h"
static int except_called = 0;
static int except_caught = 0;
struct S {
S() { except_called++; };
};
static int I = 0;
static int FuncCalled = 0;
int foo()
{
if( I==0 ) {
throw S();
}
return 1;
}
int func( int i = 2, int j = (I==0 ? throw S() : I) )
{
FuncCalled++;
return 1;
}
int funcfoo( int i = 2, int j = foo() )
{
FuncCalled++;
return 1;
}
int main()
{
I = 0;
try {
func(1);
} catch(S) {
except_caught++;
}
if( except_called != 1 || except_caught != 1 || FuncCalled != 0 ) {
fail(__LINE__);
}
try {
funcfoo(1);
} catch(S) {
except_caught++;
}
if( except_called != 2 || except_caught != 2 || FuncCalled != 0) {
fail(__LINE__);
}
I = 1;
try {
func();
funcfoo();
} catch(S) {
except_caught++;
}
if( except_called != 2 || except_caught != 2 || FuncCalled != 2) {
fail(__LINE__);
}
try {
func(1,2);
funcfoo(1,2);
} catch(S) {
except_caught++;
}
if( except_called != 2 || except_caught != 2 || FuncCalled != 4) {
fail(__LINE__);
}
_PASS;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?