1
2// TEST-OPTIONS: -arch x86_64 -framework Foundation
3// TEST-OPTIONS: -arch x86_64 -framework Foundation -Wl,-no_compact_unwind
4
5
6#include <Foundation/Foundation.h>
7
8// private SPI for AppKit
9extern int _NSAddAltHandler2(void (*proc)(NSException* exc, void* context), void* context);
10
11
12int foo() 
13{
14	@throw [NSException exceptionWithName:NSGenericException reason:@"many" userInfo:nil];
15}
16
17static void handler(NSException* exc, void* context)
18{
19	int* paltState = (int*)context;
20	*paltState = 1;
21}
22
23
24int main()
25{
26   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
27
28  	int state = 1;
29	int altState = 0;
30	@try {
31		_NSAddAltHandler2(handler, &altState);
32		state = 2;
33		foo();
34		state = 3;
35	}
36	@catch(id exception) {
37		if ( state != 2 )
38			return 1;
39		if ( altState == 0 )
40			return 1;
41		if ( [[exception name] isEqualToString:NSGenericException] ) 
42			state = 4;
43	}
44
45	if ( state == 4 )
46		return 0;
47	else
48		return 1;
49}
50
51