[interp] Remove unreachable code (#12411)
[mono-project.git] / mono / tests / exception18.cs
blob84a38a29fc9f4e80f3e1f77df6fef561ed858dba
1 using System;
2 using System.Linq;
3 using System.Runtime.CompilerServices;
5 class C
7 static Exception e;
9 static void Throw ()
11 try {
12 int.Parse (null);
13 } catch (Exception ex) {
14 e = ex;
18 static int FrameCount (Exception ex)
20 string fullTrace = ex.StackTrace;
21 string[] frames = fullTrace.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
23 // Ignore metadata
24 frames = frames.Where (l => !l.StartsWith ("[")).ToArray ();
26 return frames.Length;
29 public static void Main ()
31 Throw ();
33 try {
34 throw e;
35 } catch (Exception ex) {
36 int frames = FrameCount (ex);
37 if (frames != 1)
38 throw new Exception (String.Format("Exception carried {0} frames along with it when it should have reported one.", frames));
41 try {
42 try {
43 double.Parse ("foo");
44 } catch (Exception) {
45 throw;
47 } catch (Exception ex) {
48 int frames = FrameCount (ex);
49 if (frames != 4)
50 throw new Exception (String.Format("Exception carried {0} frames along with it when it should have reported four.", frames));
53 try {
54 new C ().M1a ();
55 } catch (Exception ex) {
56 int frames = FrameCount (ex);
57 if (frames != 4)
58 throw new Exception (String.Format("Exception carried {0} frames along with it when it should have reported four.", frames));
61 try {
62 new C ().M1b ();
63 } catch (Exception ex) {
64 int frames = FrameCount (ex);
65 if (frames != 3)
66 throw new Exception (String.Format("Exception carried {0} frames along with it when it should have reported three.", frames));
70 [MethodImpl(MethodImplOptions.NoInlining)]
71 private void M1a ()
73 M2a ();
76 [MethodImpl(MethodImplOptions.NoInlining)]
77 private void M1b ()
79 M2b ();
82 [MethodImpl(MethodImplOptions.NoInlining)]
83 private void M2a ()
85 try {
86 M3 ();
87 } catch {
88 throw;
92 [MethodImpl(MethodImplOptions.NoInlining)]
93 private void M2b ()
95 try {
96 M3 ();
97 } catch (Exception ex) {
98 throw ex;
102 [MethodImpl(MethodImplOptions.NoInlining)]
103 private void M3 ()
105 throw new NotImplementedException ();