[2020-02] Avoid following invalid pointers in mono_w32process_get_modules on Darwin...
[mono-project.git] / mono / tests / exception.cs
blob775deb8fac1dec495e4d8e04d897e4131115b44b
1 using System;
2 using System.Reflection;
3 public static class Test
5 static Test ()
7 throw new ApplicationException ();
10 public static void Foo ()
15 public class Ex {
17 int p;
18 public static int test2 () {
19 var m = typeof (Test).GetMethod ("Foo");
20 int lenStackTrace = 0;
21 try
23 m.Invoke (null, null);
25 catch (Exception e)
27 lenStackTrace = e.ToString().Length;
29 try
31 m.Invoke (null, null);
33 catch (Exception e)
35 if (lenStackTrace == e.ToString().Length)
36 return 0;
38 return 1;
40 public static int test1 () {
41 Ex x = null;
43 try {
44 x.p = 1;
45 } catch (NullReferenceException) {
46 return 0;
48 return 1;
51 public static int test (int a) {
52 int res;
53 int fin = 0;
54 try {
55 res = 10/a;
56 } catch (DivideByZeroException ex) {
57 if (fin != 1)
58 res = 34;
59 else
60 res = 33;
61 } catch {
62 if (fin != 1)
63 res = 24;
64 else
65 res = 22;
66 } finally {
67 fin = 1;
69 return res;
71 public static int Main () {
72 if (test(1) != 10)
73 return 1;
74 if (test(0) != 34)
75 return 2;
76 if (test1() != 0)
77 return 3;
78 if (test2() != 0)
79 return 4;
80 return 0;