Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/working/exception/impl/main.c

    r6b72040 r4a58895  
    11#include <stdio.h>
    22#include "except.h"
    3 
    4 // Requires -fexceptions to work.
    53
    64#define EXCEPTION 2
     
    2826extern int this_exception;
    2927_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;
    3229}
    3330
     
    3734//for details
    3835__attribute__((noinline))
    39 void try( void (*try_block)(), void (*catch_block)(),
    40           _Unwind_Reason_Code (*match_block)() )
     36void try( void (*try_block)(), void (*catch_block)() )
    4137{
    42         volatile int xy = 0;
    43         printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy);
    44 
    4538        //Setup statments
    4639        //These 2 statments won't actually result in any code,
     
    10295        "       .uleb128 .CATCH-try\n"                          //Hanlder landing pad adress  (relative to start of function)
    10396        "       .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
    10499        ".LLSDACSECFA2:\n"                                              //BODY end
    105100        "       .text\n"                                                        //TABLE footer
     
    127122
    128123        //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 );
    130125
    131126        printf( "Foo exited normally\n" );
    132127}
    133128
    134 // Not in main.cfa
    135 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.cfa
    182 
    183129int main() {
    184130        raii_t a = { "Main dtor" };
    185131
    186         //for (unsigned int i = 0 ; i < 100000000 ; ++i)
    187         foo();
    188         fee();
     132        for (unsigned int i = 0 ; i < 100000000 ; ++i) foo();
    189133
    190134        printf("End of program reached\n");
Note: See TracChangeset for help on using the changeset viewer.