[runtime] Overwrite stacktrace for exception on re-throw. Fixes #1856.
[mono.git] / mono / tests / cas / linkdemand / pinvoke1.cs
1 using System;
2 using System.Runtime.InteropServices;
3 using System.Security;
4
5 // this attribute has NO effect on LinkDemand!
6 [SuppressUnmanagedCodeSecurity]
7 public class Program {
8
9         // for Mono
10         [DllImport ("libc", SetLastError=true)]
11         public static extern uint getuid ();
12
13         // for Microsoft
14         [DllImport ("kernel32.dll", SetLastError=true)]
15         public static extern uint GetTickCount ();
16
17         static bool RunningOnMono ()
18         {
19                 bool mono = (Type.GetType ("Mono.Math.BigInteger") != null); 
20                 Console.WriteLine ("Running on {0} runtime...", mono ? "Mono" : "Microsoft");
21                 return mono;
22         }
23
24         static int Test ()
25         {
26                 try {
27                         uint u = (RunningOnMono ()) ? getuid () : GetTickCount ();
28                         Console.WriteLine ("*0* P/Invoke: {0}", u);
29                         return 0;
30                 }
31                 catch (SecurityException se) {
32                         Console.WriteLine ("*1* Unexpected SecurityException\n{0}", se);
33                         return 1;
34                 }
35                 catch (Exception e) {
36                         Console.WriteLine ("*2* Unexpected exception\n{0}", e);
37                         return 2;
38                 }
39         }
40
41         static int Main ()
42         {
43                 return Test ();
44         }
45 }