2 using System.Runtime.InteropServices;
6 [DllImport ("libtest")]
7 static extern void mono_test_native_to_managed_exception_rethrow (Action action);
10 static extern void _exit (int exitCode);
12 static int Main (string[] args)
14 AppDomain.CurrentDomain.UnhandledException += (sender, exception_args) =>
16 CustomException exc = exception_args.ExceptionObject as CustomException;
18 Console.WriteLine ($"FAILED - Unknown exception: {exception_args.ExceptionObject}");
22 Console.WriteLine (exc.StackTrace);
23 if (string.IsNullOrEmpty (exc.StackTrace)) {
24 Console.WriteLine ("FAILED - StackTrace is null for unhandled exception.");
27 Console.WriteLine ("SUCCESS - StackTrace is not null for unhandled exception.");
32 mono_test_native_to_managed_exception_rethrow (PlainThrow);
33 Console.WriteLine ("Should have exited in the UnhandledException event handler.");
37 static void PlainThrow ()
44 throw new CustomException ("C");
47 class CustomException : Exception
49 public CustomException(string s) : base(s) {}