Example

using System;

namespace Samples
{
  public class IndexOutOfRangeExceptionSample
  {
    public static void Main()
    {
      try
      {
        string[] strings = {"zero", "one", "two"};
        strings[3] = "three";
      }
      catch(Exception e)
      {
        Console.WriteLine("Exception: {0}", e);
      }
    }
  }
}
The output is
Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Samples.IndexOutOfRangeExceptionSample.Main() in C:\Books\BCL\Samples\
System\IndexOutOfRangeException\IndexOutOfRangeException.cs:line 12

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.