- File:
-
- 1 edited
-
doc/working/exception/impl/main.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/working/exception/impl/main.c
r6b72040 r4a58895 1 1 #include <stdio.h> 2 2 #include "except.h" 3 4 // Requires -fexceptions to work.5 3 6 4 #define EXCEPTION 2 … … 28 26 extern int this_exception; 29 27 _Unwind_Reason_Code foo_try_match() { 30 printf(" (foo_try_match called)"); 31 return this_exception == EXCEPTION ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND; 28 return this_exception == 3 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND; 32 29 } 33 30 … … 37 34 //for details 38 35 __attribute__((noinline)) 39 void try( void (*try_block)(), void (*catch_block)(), 40 _Unwind_Reason_Code (*match_block)() ) 36 void try( void (*try_block)(), void (*catch_block)() ) 41 37 { 42 volatile int xy = 0;43 printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy);44 45 38 //Setup statments 46 39 //These 2 statments won't actually result in any code, … … 102 95 " .uleb128 .CATCH-try\n" //Hanlder landing pad adress (relative to start of function) 103 96 " .uleb128 1\n" //Action code, gcc seems to use always 0 97 //Beyond this point we don't match gcc data' 98 " .uleb128 foo_try_match-try\n" //Handler routine to check if the exception is matched 104 99 ".LLSDACSECFA2:\n" //BODY end 105 100 " .text\n" //TABLE footer … … 127 122 128 123 //Actual call to the try block 129 try( foo_try_block, foo_catch_block , foo_try_match);124 try( foo_try_block, foo_catch_block ); 130 125 131 126 printf( "Foo exited normally\n" ); 132 127 } 133 128 134 // Not in main.cfa135 void fy() {136 // Currently not destroyed if the exception is caught in fee.137 raii_t a = { "Fy dtor" };138 139 void fy_try_block() {140 raii_t b = { "Fy try dtor" };141 142 throw( 3 );143 }144 145 void fy_catch_block() {146 printf("Fy caught exception\n");147 }148 149 _Unwind_Reason_Code fy_match_block() {150 return this_exception == 2 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;151 }152 153 try(fy_try_block, fy_catch_block, fy_match_block);154 155 printf( "Fy exited normally\n" );156 }157 158 void fee() {159 raii_t a = { "Fee dtor" };160 161 void fee_try_block() {162 raii_t b = { "Fee try dtor" };163 164 fy();165 166 printf("fy returned\n");167 }168 169 void fee_catch_block() {170 printf("Fee caught exception\n");171 }172 173 _Unwind_Reason_Code fee_match_block() {174 return this_exception == 3 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;175 }176 177 try(fee_try_block, fee_catch_block, fee_match_block);178 179 printf( "Fee exited normally\n" );180 }181 // End not in main.cfa182 183 129 int main() { 184 130 raii_t a = { "Main dtor" }; 185 131 186 //for (unsigned int i = 0 ; i < 100000000 ; ++i) 187 foo(); 188 fee(); 132 for (unsigned int i = 0 ; i < 100000000 ; ++i) foo(); 189 133 190 134 printf("End of program reached\n");
Note:
See TracChangeset
for help on using the changeset viewer.