[System.ServiceModel] Prevent crash in Dispatcher.ListenerLoopManager… (#7136)
[mono-project.git] / mono / tests / bug-58782-plain-throw.cs
blob72ce01cb16e2c9c2f70427460e589ed819529e4b
1 using System;
2 using System.Runtime.InteropServices;
4 class Driver
6 [DllImport ("libtest")]
7 static extern void mono_test_native_to_managed_exception_rethrow (Action action);
9 [DllImport ("libc")]
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;
17 if (exc == null) {
18 Console.WriteLine ($"FAILED - Unknown exception: {exception_args.ExceptionObject}");
19 _exit (1);
22 Console.WriteLine (exc.StackTrace);
23 if (string.IsNullOrEmpty (exc.StackTrace)) {
24 Console.WriteLine ("FAILED - StackTrace is null for unhandled exception.");
25 _exit (2);
26 } else {
27 Console.WriteLine ("SUCCESS - StackTrace is not null for unhandled exception.");
28 _exit (0);
32 mono_test_native_to_managed_exception_rethrow (PlainThrow);
33 Console.WriteLine ("Should have exited in the UnhandledException event handler.");
34 return 3;
37 static void PlainThrow ()
39 Throw ();
42 static void Throw ()
44 throw new CustomException ("C");
47 class CustomException : Exception
49 public CustomException(string s) : base(s) {}