main.c


1
#include <stdio.h>
2
#include "custom_exception.h"
3
4
void testfunc(){
5
  printf( "testfunc begin\n" );
6
  throw( test_exception, (
7
    .message = "This is a test_exception"
8
  ));
9
  printf( "testfunc end\n" );
10
}
11
12
void testfunc2(){
13
  printf( "testfunc2 begin\n" );
14
  try {
15
    printf( "testfunc2 try start\n" );
16
    testfunc();
17
    printf( "testfunc2 try end\n" );
18
  } finally( e ) {
19
    printf( "testfunc2 finally start\n" );
20
    rethrow();
21
    printf( "testfunc2 finally end\n" );
22
  }
23
  printf( "testfunc2 end\n" );
24
}
25
26
27
int main(){
28
29
  printf( "main begin\n" );
30
31
  try {
32
33
    printf( "try start\n" );
34
    testfunc2();
35
    printf( "try end\n" );
36
37
  } catch( test_exception, e ) {
38
39
    printf( "catched exception: %s\n", e->message );
40
41
  } finally( e ) {
42
43
    printf( "finally\n" );
44
45
  }
46
47
  printf( "main end\n" );
48
49
}