2009-06-12 Bill Holmes <billholmes54@gmail.com>
[mono.git] / mcs / nunit20 / util / TestExceptionHandler.cs
1 using System;
2
3 namespace NUnit.Util
4 {
5         /// <summary>
6         /// Summary description for UnhandledExceptionCatcher.
7         /// </summary>
8         public class TestExceptionHandler : IDisposable
9         {
10                 private UnhandledExceptionEventHandler handler;
11
12                 public TestExceptionHandler( UnhandledExceptionEventHandler handler )
13                 {
14 #if !TARGET_JVM
15                         this.handler = handler;
16                         AppDomain.CurrentDomain.UnhandledException += handler;
17 #endif
18                 }
19
20                 ~TestExceptionHandler()
21                 {
22 #if  !TARGET_JVM
23                         if ( handler != null )
24                         {
25                                 AppDomain.CurrentDomain.UnhandledException -= handler;
26                                 handler = null;
27                         }
28 #endif
29                 }
30
31
32
33                 public void Dispose()
34                 {
35 #if !TARGET_JVM
36                         if ( handler != null )
37                         {
38                                 AppDomain.CurrentDomain.UnhandledException -= handler;
39                                 handler = null;
40                         }
41
42                         System.GC.SuppressFinalize( this );
43 #endif
44                 }
45         }
46 }