Advertisement
Guest User

Finalizer exception + AppDomain.UnhandledException

a guest
Oct 9th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication2
  8. {
  9.     class Program
  10.     {
  11.         static void Main( string[] args )
  12.         {
  13.             AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
  14.  
  15.             Buggy instance = new Buggy();
  16.             Console.WriteLine( instance );
  17.            
  18.             instance = null;
  19.             GC.Collect();
  20.             GC.WaitForPendingFinalizers();
  21.         }
  22.  
  23.         static void OnUnhandledException( object sender, UnhandledExceptionEventArgs e )
  24.         {
  25.             Console.WriteLine( e.ExceptionObject );
  26.         }
  27.     }
  28.  
  29.     class Buggy
  30.     {
  31.         ~Buggy()
  32.         {
  33.             throw new Exception();
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement