ADT
arm-eh
ast-experimental
enum
forall-pointer-decay
jacob/cs343-translation
new-ast
new-ast-unique-expr
pthread-emulation
qualifiedEnum
Last change
on this file since 6c12fd28 was e68d092, checked in by Andrew Beach <ajbeach@…>, 5 years ago |
Replaced my exception patch macros with a (hopefully temporary) addition to the standard libary, the same macros just cleaned up. See the exception tests for some example uses.
|
-
Property mode
set to
100644
|
File size:
1002 bytes
|
Line | |
---|
1 | // Test exceptions that add data but no functionality.
|
---|
2 |
|
---|
3 | #include <exception.hfa>
|
---|
4 |
|
---|
5 | DATA_EXCEPTION(paired)(
|
---|
6 | int first;
|
---|
7 | int second;
|
---|
8 | );
|
---|
9 |
|
---|
10 | void ?{}(paired & this, int first, int second) {
|
---|
11 | VTABLE_INIT(this, paired);
|
---|
12 | this.first = first;
|
---|
13 | this.second = second;
|
---|
14 | }
|
---|
15 |
|
---|
16 | void copy(paired * this, paired * other) {
|
---|
17 | *this = *other;
|
---|
18 | }
|
---|
19 |
|
---|
20 | const char * paired_msg(paired * this) {
|
---|
21 | return "paired";
|
---|
22 | }
|
---|
23 |
|
---|
24 | VTABLE_INSTANCE(paired)(paired_msg);
|
---|
25 |
|
---|
26 | void throwPaired(int first, int second) {
|
---|
27 | paired exc = {first, second};
|
---|
28 | }
|
---|
29 |
|
---|
30 | int main(int argc, char * argv[]) {
|
---|
31 | paired except = {3, 13};
|
---|
32 |
|
---|
33 | try {
|
---|
34 | throw &except;
|
---|
35 | } catch (paired * exc) {
|
---|
36 | printf("%s(%d, %d)\n", paired_msg(exc), exc->first, exc->second);
|
---|
37 | ++exc->first;
|
---|
38 | }
|
---|
39 |
|
---|
40 | printf("%s(%d, %d)\n", paired_msg(&except), except.first, except.second);
|
---|
41 |
|
---|
42 | try {
|
---|
43 | throwResume &except;
|
---|
44 | } catchResume (paired * exc) {
|
---|
45 | printf("%s(%d, %d)\n", paired_msg(exc), exc->first, exc->second);
|
---|
46 | ++exc->first;
|
---|
47 | }
|
---|
48 |
|
---|
49 | printf("%s(%d, %d)\n", paired_msg(&except), except.first, except.second);
|
---|
50 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.