source:
doc/theses/andrew_beach_MMath/code/cond-catch.cfa
@
790d835
Last change on this file since 790d835 was f79ee0d, checked in by , 3 years ago | |
---|---|
|
|
File size: 868 bytes |
Rev | Line | |
---|---|---|
[ea593a3] | 1 | // Conditional Match (or Re-Raise) |
[ee23a8d] | 2 | #include <clock.hfa> |
[ea593a3] | 3 | #include <exception.hfa> |
[ee23a8d] | 4 | #include <fstream.hfa> |
[f79ee0d] | 5 | #include <stdlib.hfa> // strto |
[ea593a3] | 6 | |
[f79ee0d] | 7 | exception empty_exception; |
8 | vtable(empty_exception) empty_vt; | |
[ea593a3] | 9 | |
10 | bool should_catch = false; | |
11 | ||
12 | int main(int argc, char * argv[]) { | |
13 | unsigned int times = 1; | |
[ee23a8d] | 14 | if (1 < argc) { |
[f79ee0d] | 15 | times = strto(argv[1], 0p, 10); |
[ea593a3] | 16 | } |
[11ad42f] | 17 | if (2 < argc) { |
[f79ee0d] | 18 | should_catch = (unsigned int)strto(argv[2], 0p, 2); |
[11ad42f] | 19 | } |
[ea593a3] | 20 | |
[47e413b] | 21 | Time start_time = timeHiRes(); |
[ea593a3] | 22 | for (unsigned int count = 0 ; count < times ; ++count) { |
23 | try { | |
[f79ee0d] | 24 | throw (empty_exception){&empty_vt}; |
25 | } catch (empty_exception * exc ; should_catch) { | |
26 | asm volatile ("# catch block (conditional)"); | |
[ea593a3] | 27 | } catch (empty_exception * exc) { |
[54651005] | 28 | asm volatile ("# catch block (unconditional)"); |
[ea593a3] | 29 | } |
30 | } | |
[47e413b] | 31 | Time end_time = timeHiRes(); |
[f79ee0d] | 32 | sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.); |
[ea593a3] | 33 | } |
Note: See TracBrowser
for help on using the repository browser.