[runtime] Overwrite stacktrace for exception on re-throw. Fixes #1856.
[mono.git] / mono / tests / cas / linkdemand / refcas3.cs
1 using System;
2 using System.Reflection;
3 using System.Security;
4 using System.Security.Permissions;
5
6 public class Program {
7
8         [SecurityPermission (SecurityAction.LinkDemand, ControlPrincipal=true)]
9         public static int Test ()
10         {
11                 return 3;
12         }
13
14         [SecurityPermission (SecurityAction.Deny, ControlPrincipal=true)]
15         static int TestReflectedCall ()
16         {
17                 MethodInfo mi = typeof (Program).GetMethod ("Test", BindingFlags.Static | BindingFlags.Public);
18                 if (mi == null) {
19                         Console.WriteLine ("*1* Couldn't reflect on call Test (abnormal).");
20                         return 1;
21                 }
22                 Console.WriteLine ("*0* Reflected on call Test (normal).");
23                 // but invoking would throw a SecurityException!
24                 return 0;
25         }
26
27         [SecurityPermission (SecurityAction.Deny, ControlPrincipal=true)]
28         static int Main ()
29         {
30                 try {
31                         return TestReflectedCall ();
32                 }
33                 catch (SecurityException se) {
34                         Console.WriteLine ("*2* Unexpected SecurityException.\n{0}", se);
35                         return 2;
36                 }
37                 catch (Exception e) {
38                         Console.WriteLine ("*3* Unexpected Exception.\n{0}", e);
39                         return 3;
40                 }
41         }
42 }