Example

using System;
using System.Collections;

namespace Samples
{
  public class InvalidOperationExceptionSample
  {
    public static void Main()
    {
      try
      {
        string[] strings = {"zero", "one", "two"};
        IEnumerator ie = strings.GetEnumerator();
        Console.Write("{0}", ie.Current);
      }
      catch(InvalidOperationException e)
      {
        Console.WriteLine("Exception: {0}", e);
      }
    }
  }
}
The output is
Exception: System.InvalidOperationException: Enumeration has not started. Call MoveNext.
   at System.SZArrayEnumerator.get_Current()
   at Samples.InvalidOperationExceptionSample.Main() in C:\Books\BCL\Samples\
System\InvalidOperationException\InvalidOperationException.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.