source: doc/theses/andrew_beach_MMath/code/cond-match.cpp@ cf444b6

ADT ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since cf444b6 was ea593a3, checked in by Andrew Beach <ajbeach@…>, 4 years ago

First draft of all the exception benchmarks. There is an issue with the Cforall linking.

  • Property mode set to 100644
File size: 698 bytes
Line 
1// Conditional Match (or Re-Raise)
2#include <exception>
3#include <cstdlib>
4
5struct EmptyException : public std::exception {};
6
7bool should_catch = false;
8
9void throw_exception() {
10 throw EmptyException();
11}
12
13void cond_catch() {
14 try {
15 throw_exception();
16 } catch (EmptyException & exc) {
17 if (should_catch) {
18 throw;
19 }
20 }
21}
22
23int main(int argc, char * argv[]) {
24 unsigned int times = 1;
25 unsigned int total_frames = 1;
26 if (2 < argc) {
27 times = strtol(argv[1], nullptr, 10);
28 }
29 if (3 < argc) {
30 total_frames = strtol(argv[2], nullptr, 10);
31 }
32
33 for (unsigned int count = 0 ; count < times ; ++count) {
34 try {
35 cond_catch();
36 } catch (EmptyException &) {
37 // ...
38 }
39 }
40}
Note: See TracBrowser for help on using the repository browser.