2 using System.Threading;
4 public class MultiThreadExceptionTest {
6 public static int result = 0;
8 public static void ThreadStart1 () {
9 Console.WriteLine("{0} started",
10 Thread.CurrentThread.Name);
18 Console.WriteLine ("Count: " + i++);
22 catch (ThreadAbortException e) {
23 Console.WriteLine ("cought exception level 3 ");
25 // Check that the exception is only rethrown in
26 // the appropriate catch clauses
32 throw new DivideByZeroException ();
38 // Check that the exception is properly rethrown
41 } catch (ThreadAbortException e) {
42 Console.WriteLine ("cought exception level 2 " + e.ExceptionState);
43 Console.WriteLine (e);
44 if ((string)e.ExceptionState == "STATETEST")
50 } catch (ThreadAbortException e) {
51 Console.WriteLine ("cought exception level 1 " + e.ExceptionState);
52 Console.WriteLine (e);
53 if (e.ExceptionState == null)
56 } catch (Exception e) {
57 Console.WriteLine ("cought exception level 0")
58 ; Console.WriteLine (e);
59 Console.WriteLine (e.StackTrace);
65 } catch (System.Threading.ThreadStateException e) {
69 Console.WriteLine ("end");
73 public static int Main() {
75 // Check aborting the current thread
78 Thread.CurrentThread.Abort ();
87 Thread t1 = new Thread(new ThreadStart
88 (MultiThreadExceptionTest.ThreadStart1));
96 t1.Abort ("STATETEST");
99 Console.WriteLine ("Result: " + result);