2 using System
.Threading
;
3 using System
.Reflection
;
4 using System
.Reflection
.Emit
;
5 using System
.Runtime
.ExceptionServices
;
6 using System
.Diagnostics
;
10 public static Exception Caught
;
12 public static void ThrowMe()
17 throw new Exception("test");
24 var edi
= ExceptionDispatchInfo
.Capture(e
);
29 public static void Handler(Exception e
)
37 public static int Main()
40 string expected
= A
.Caught
.StackTrace
.ToString ();
42 for (int i
= 0; i
< 1000; ++i
) {
43 Thread t
= new Thread (delegate () {
49 GC
.WaitForPendingFinalizers ();
50 if (A
.Caught
.StackTrace
!= expected
) {
51 Console
.WriteLine ("FAILED");
60 DynamicMethod multiplyHidden
= new DynamicMethod(
62 typeof(void), new[] { typeof(int) }
, typeof(Example
));
64 ILGenerator ig
= multiplyHidden
.GetILGenerator();
66 ig
.BeginExceptionBlock();
68 ig
.Emit(OpCodes
.Call
, typeof(A
).GetMethod("ThrowMe"));
70 ig
.BeginCatchBlock(typeof(Exception
));
72 ig
.Emit(OpCodes
.Call
, typeof(A
).GetMethod("Handler"));
74 ig
.EndExceptionBlock();
78 var invoke
= (Action
<int>)
79 multiplyHidden
.CreateDelegate(