Example

using System;
using System.IO;

namespace Samples
{
  public class ObjectDisposedExceptionSample
  {
    public static void Main()
    {
      MemoryStream ms = new MemoryStream(16);
      ms.Close();
      try
      {
        ms.ReadByte();
      }
      catch(ObjectDisposedException e)
      {
        Console.WriteLine("Exception: {0}", e);
      }
    }
  }
}
The output is
Exception: System.ObjectDisposedException: Cannot access a closed Stream.
   at System.IO.__Error.StreamIsClosed()
   at System.IO.MemoryStream.ReadByte()
   at Samples.ObjectDisposedExceptionSample.Main() in C:\Books\BCL\Samples\System\
ObjectDisposedException\ObjectDisposedException.cs:line 14

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.