X-Git-Url: http://git.harvie.cz/?p=svn%2FCll1h%2F.git;a=blobdiff_plain;f=demos%2Fexceptions%2Ffailures.c;fp=demos%2Fexceptions%2Ffailures.c;h=2338f7f9d59f331783cc189e715a37b02d99b2a4;hp=0000000000000000000000000000000000000000;hb=eac5d6c70c3babc9056f059edd88a2c1a82bc7e9;hpb=7e4d757514e0d9904d6b31b5a08760eff306a9f2 diff --git a/demos/exceptions/failures.c b/demos/exceptions/failures.c new file mode 100644 index 0000000..2338f7f --- /dev/null +++ b/demos/exceptions/failures.c @@ -0,0 +1,75 @@ +#include "cll1.h" + +void some_function(int i) +{ + if(i==2) + { + fail(EVIL_FAILURE); + } + if(i==7) + { + some_function(2); + } + if(i==6) + { + fail(LOCAL_FAILURE); + } + printf("nuda #%d\n",i); +} + +program +{ + try + { + some_function(1); + some_function(2); + some_function(6); + } + else_switch_failures + { + case EVIL_FAILURE: puts("serious failure detected!"); break; + default: puts("sorry, vole, error!"); + } + + try + { + some_function(1); + some_function(3); + some_function(6); + some_function(2); + } + else + { + puts("sorry, vole, error!"); + } + + try + { + some_function(1); + some_function(6); + } + else_catch(EVIL_FAILURE) + { + puts("Totally screwed."); + exit(-1); + } + else + { + puts("We survived this failure."); + } + + try + { + some_function(3); + some_function(7); + } + else_catch(EVIL_FAILURE) + { + puts("totally screwed."); + exit(-1); + } + else + { + puts("we survived this failure."); + } +}