1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
/*
* Copyright (c) 2008
* Jonathan Schleifer <js@webkeks.org>
*
* All rights reserved.
*
* This file is part of libobjfw. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE included in
* the packaging of this file.
*/
#import <stdio.h>
#import <stdlib.h>
#import <stdbool.h>
#import "OFObject.h"
#import "OFExceptions.h"
#define CATCH_EXCEPTION(code, exception) \
caught = false; \
@try { \
code; \
} @catch (exception *e) { \
caught = true; \
puts("CAUGHT! Error string was:"); \
fputs([e cString], stdout); \
puts("Resuming..."); \
} \
if (!caught) { \
puts("NOT CAUGHT!"); \
return 1; \
}
int
main()
{
OFObject *obj = [OFObject new];
bool caught;
void *p, *q, *r;
/* Test freeing memory not allocated by obj */
puts("Freeing memory not allocated by object (should throw an "
"exception)...");
CATCH_EXCEPTION([obj freeMem: NULL], OFMemNotPartOfObjException)
|
<
|
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/*
* Copyright (c) 2008
* Jonathan Schleifer <js@webkeks.org>
*
* All rights reserved.
*
* This file is part of libobjfw. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE included in
* the packaging of this file.
*/
#import <stdio.h>
#import <stdlib.h>
#import "OFObject.h"
#import "OFExceptions.h"
#define CATCH_EXCEPTION(code, exception) \
caught = NO; \
@try { \
code; \
} @catch (exception *e) { \
caught = YES; \
puts("CAUGHT! Error string was:"); \
fputs([e cString], stdout); \
puts("Resuming..."); \
} \
if (!caught) { \
puts("NOT CAUGHT!"); \
return 1; \
}
int
main()
{
OFObject *obj = [OFObject new];
BOOL caught;
void *p, *q, *r;
/* Test freeing memory not allocated by obj */
puts("Freeing memory not allocated by object (should throw an "
"exception)...");
CATCH_EXCEPTION([obj freeMem: NULL], OFMemNotPartOfObjException)
|