Merge pull request #2799 from BrzVlad/fix-conc-card-clean
[mono.git] / mono / tests / unhandled-exception-7.cs
index d31fdf9e025ecdbcb0826cc374d3e088961d6379..87c5fbb8cb17137e5df5aebcfccd7edfe88d11c9 100644 (file)
@@ -2,15 +2,12 @@ using System;
 using System.Diagnostics;
 using System.Threading;
 using System.Threading.Tasks;
+using System.Runtime.Remoting.Messaging;
 
 class CustomException : Exception
 {
 }
 
-class CustomException2 : Exception
-{
-}
-
 class CrossDomain : MarshalByRefObject
 {
        public Action NewDelegateWithTarget ()
@@ -31,25 +28,31 @@ class CrossDomain : MarshalByRefObject
 
 class Driver
 {
-       /* expected exit code: 0 */
+       /* expected exit code: 255 */
        static void Main (string[] args)
        {
+               if (Environment.GetEnvironmentVariable ("TEST_UNHANDLED_EXCEPTION_HANDLER") != null)
+                       AppDomain.CurrentDomain.UnhandledException += (s, e) => {};
+
                ManualResetEvent mre = new ManualResetEvent (false);
 
-               var cd = (CrossDomain) AppDomain.CreateDomain ("ad").CreateInstanceAndUnwrap (typeof(CrossDomain).Assembly.FullName, "CrossDomain");
+               var ad = AppDomain.CreateDomain ("ad");
+
+               if (Environment.GetEnvironmentVariable ("TEST_UNHANDLED_EXCEPTION_HANDLER") != null)
+                       ad.UnhandledException += (s, e) => {};
 
-               var a = cd.NewDelegateWithoutTarget ();
-               var ares = a.BeginInvoke (delegate { throw new CustomException2 (); }, null);
+               var cd = (CrossDomain) ad.CreateInstanceAndUnwrap (typeof(CrossDomain).Assembly.FullName, "CrossDomain");
 
-               try {
-                       a.EndInvoke (ares);
-                       Environment.Exit (4);
-               } catch (CustomException) {
-               } catch (Exception ex) {
-                       Console.WriteLine (ex);
-                       Environment.Exit (3);
-               }
+               var action = cd.NewDelegateWithoutTarget ();
+               var ares = action.BeginInvoke (Callback, null);
 
-               Environment.Exit (0);
+               Thread.Sleep (5000);
+
+               Environment.Exit (1);
+       }
+
+       static void Callback (IAsyncResult iares)
+       {
+               ((Action) ((AsyncResult) iares).AsyncDelegate).EndInvoke (iares);
        }
 }