1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for
3 // full license information.
4 
5 #include <stdio.h>
6 #include <windows.h>
7 #ifdef _M_CEE
8 #define MAX_REC 200
9 #else
10 #define MAX_REC 200
11 #endif
12 
13 #define NLOOPS 10
14 
15 #if defined(_M_SH) || defined(TRISC)
16 #undef MAX_REC
17 #define MAX_REC 3
18 #endif
19 
20 #if defined(_M_AMD64)
21 #undef MAX_REC
22 #define MAX_REC 50
23 #endif
24 
25 void foo(int level)
26 {
27     if(level < MAX_REC)
28     {
29         try
30         {
31             foo(level+1);
32         }
33         catch(int& throw_level)
34         {
35             //printf("Level %d catched level %d\n",level,throw_level);
36             throw_level = level;
37             //printf("Level %d throwing\n",level);
38             throw level;
39         }
40     }
41     else
42     {
43         printf("Level MAX_REC throwing.\n");
44         throw level;
45     }
46 }
47 
48 int main(void)
49 {
50     int n;
51     LARGE_INTEGER freq,start,end;
52 
53 #if !defined(_M_AMD64) && !defined(_M_ARM) && !defined(_M_ARM64)
54     QueryPerformanceFrequency(&freq);
55     QueryPerformanceCounter(&start);
56 #endif
57 
58     //printf("Max Recursion level: %d\n", MAX_REC);
59     printf("N loops: %d\n", NLOOPS);
60 
61     for(n=0;n<NLOOPS;n++)
62     {
63         try
64         {
65             foo(0);
66         }
67         catch(int& throw_level)
68         {
69             printf("main catched level %d\n",throw_level);
70         }
71     }
72 #if !defined(_M_AMD64) && !defined(_M_ARM) && !defined(_M_ARM64)
73     QueryPerformanceCounter(&end);
74 #endif
75 
76     //printf("Exceptions per sec %lf\n",(double)(NLOOPS*MAX_REC)/((double)(end.QuadPart-start.QuadPart)/(double)freq.QuadPart));
77 }
78