2005-08-08 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mono / tests / thread6.cs
index eb7079637e18caf5a8b314a2350a449e830eebf3..f7910b2c9ba2ca36335a221f780dbf0b18d0bfc3 100644 (file)
@@ -11,17 +11,44 @@ public class MultiThreadExceptionTest {
 
                try {
                        try {
-                               int i = 0;
                                try {
-                                       while (true) {
-                                               Console.WriteLine ("Count: " + i++);
-                                               Thread.Sleep (100);
+                                       int i = 0;
+                                       try {
+                                               while (true) {
+                                                       Console.WriteLine ("Count: " + i++);
+                                                       Thread.Sleep (100);
+                                               }
                                        }
+                                       catch (ThreadAbortException e) {
+                                               Console.WriteLine ("cought exception level 3 ");
+
+                                               // Check that the exception is only rethrown in
+                                               // the appropriate catch clauses
+
+                                               // This doesn't work currently, see
+                                               // http://bugzilla.ximian.com/show_bug.cgi?id=68552
+
+                                               /*
+                                               try {
+                                               }
+                                               catch {}
+                                               try {
+                                                       throw new DivideByZeroException ();
+                                               }
+                                               catch (Exception) {
+                                               }
+                                               */
+                                               result |= 32;
+
+                                               // Check that the exception is properly rethrown
+                                       }
+                                       result = 255;
                                } catch (ThreadAbortException e) {
                                        Console.WriteLine ("cought exception level 2 " + e.ExceptionState);
                                        Console.WriteLine (e);
                                        if ((string)e.ExceptionState == "STATETEST")
                                                result |= 1;
+
                                        Thread.ResetAbort ();
                                        throw e;
                                }
@@ -32,8 +59,9 @@ public class MultiThreadExceptionTest {
                                        result |= 2;
                        }
                } catch (Exception e) {
-                       Console.WriteLine ("cought exception level 0");
-                       Console.WriteLine (e);
+                       Console.WriteLine ("cought exception level 0")
+;                      Console.WriteLine (e);
+                       Console.WriteLine (e.StackTrace);
                        result |= 4;
                }
 
@@ -48,6 +76,19 @@ public class MultiThreadExceptionTest {
        }
        
        public static int Main() {
+
+               // Check aborting the current thread
+               bool aborted = false;
+               try {
+                       Thread.CurrentThread.Abort ();
+               }
+               catch {
+                       aborted = true;
+                       Thread.ResetAbort ();
+               }
+               if (!aborted)
+                       return 2;
+
                Thread t1 = new Thread(new ThreadStart
                        (MultiThreadExceptionTest.ThreadStart1));
                t1.Name = "Thread 1";
@@ -55,9 +96,6 @@ public class MultiThreadExceptionTest {
                Thread.Sleep (100);
                
                t1.Start();
-
-               //Thread t0 = Thread.CurrentThread;
-               //t0.Abort ();
                
                Thread.Sleep (200);
                t1.Abort ("STATETEST");
@@ -65,10 +103,32 @@ public class MultiThreadExceptionTest {
                t1.Join ();
                Console.WriteLine ("Result: " + result);
 
-               if (result != 27)
+               if (result != 59)
                        return 1;
 
+               // Test from #68552
+               try {
+                       try {
+                               Run ();
+                       } catch (Exception ex) {
+                       }
+
+                       return 2;
+               }
+               catch (ThreadAbortException ex) {
+                       Thread.ResetAbort ();
+               }
+
                return 0;
        }
+
+       public static void Run ()
+       {
+               try {
+                       Thread.CurrentThread.Abort ();
+               } catch (Exception ex) {
+                       throw new Exception ("other");
+               }
+       }
 }