- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/andrew_beach_MMath/code/cond-catch.cfa
rf79ee0d r54651005 3 3 #include <exception.hfa> 4 4 #include <fstream.hfa> 5 #include <stdlib.h fa> // strto5 #include <stdlib.h> 6 6 7 exception empty_exception; 8 vtable(empty_exception) empty_vt; 7 EHM_EXCEPTION(empty_exception)(); 8 9 EHM_VIRTUAL_TABLE(empty_exception, empty_vt); 9 10 10 11 bool should_catch = false; 12 13 void throw_exception() { 14 throw (empty_exception){&empty_vt}; 15 } 16 17 void cond_catch() { 18 try { 19 throw_exception(); 20 } catch (empty_exception * exc ; should_catch) { 21 asm volatile ("# catch block (conditional)"); 22 } 23 } 11 24 12 25 int main(int argc, char * argv[]) { 13 26 unsigned int times = 1; 14 27 if (1 < argc) { 15 times = strto (argv[1], 0p, 10);28 times = strtol(argv[1], 0p, 10); 16 29 } 17 30 if (2 < argc) { 18 should_catch = (unsigned int)strto(argv[2], 0p, 2);31 should_catch = strtol(argv[2], 0p, 10); 19 32 } 20 33 … … 22 35 for (unsigned int count = 0 ; count < times ; ++count) { 23 36 try { 24 throw (empty_exception){&empty_vt}; 25 } catch (empty_exception * exc ; should_catch) { 26 asm volatile ("# catch block (conditional)"); 37 cond_catch(); 27 38 } catch (empty_exception * exc) { 28 39 asm volatile ("# catch block (unconditional)"); … … 30 41 } 31 42 Time end_time = timeHiRes(); 32 sout | "Run-Time ( s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);43 sout | "Run-Time (ns): " | (end_time - start_time)`ns; 33 44 }
Note: See TracChangeset
for help on using the changeset viewer.