source: doc/working/exception/main.cfa @ 4cfcf41

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 4cfcf41 was ae6f1ec, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Some work on an exception prototype

  • Property mode set to 100644
File size: 510 bytes
Line 
1#include <stdio.h>
2#include "except.h"
3
4struct raii_t {
5        char * msg;
6};
7
8void ^?{}( type_raii_t * this ) {
9        printf("%s\n", this->msg);
10}
11
12void bar() {
13        raii_t a = { "Bar dtor" };
14
15        throw( 3 );
16}
17
18void foo() {
19        raii_t a = { "Foo dtor" };
20
21        try {
22                raii_t b = { "Foo try dtor" };
23
24                bar();
25
26                printf("Called bar successfully\n");
27        }
28        catch( 2 ) {
29                printf("Exception caught\n");
30        }
31
32        printf( "Foo exited normally\n" );
33}
34
35int main() {
36        raii_t a = { "Main dtor" };
37
38        foo();
39
40        printf("End of program reached\n");
41}
Note: See TracBrowser for help on using the repository browser.