0

I was trying to understand the behavior of Dispose at time of the exception. I wrote below program.

class Program
{
    static void Main()
    {
       using (var d = new MyDisposable())
       {
         throw new Exception("Hello");
       }
    }

 class MyDisposable : IDisposable
 {
    public void Dispose()
    {
        Console.WriteLine("Disposed"); //Debugger at this line 
    }
 }
}

When I tried to Debug this code by having Debugger at Dispose, my Debugger is not getting hit.

Please Help.

  • 1
    instead, the debugger breaks showing you an exception, right? – dymanoid Jul 20 '18 at 11:31
  • 1
    Ignore the [first duplicate](https://stackoverflow.com/questions/31026257/idisposable-dispose-is-never-called-after-exception-in-using-block). The [second](https://stackoverflow.com/questions/47153806/why-dispose-is-not-called-even-with-using-statement) is what explains this – Tim Schmelter Jul 20 '18 at 11:45

0 Answers0