Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System;
  2.  
  3. namespace Articulos.Cap04.Excepciones.Parte5
  4. {
  5.     public sealed class UsoIndexOutOfRangeException
  6.     {
  7.         public static void Main()
  8.         {
  9.             int[] arregloEnteros = new int[5];
  10.            
  11.             // Agrega 5 elementos al arreglo:
  12.             for (int i = 0; i < arregloEnteros.Length; ++i)
  13.             {
  14.                 arregloEnteros[i] = i + 1;
  15.             }
  16.            
  17.             try
  18.             {
  19.                 // Intengo de acceder a un elemento del
  20.                 // arreglo con un índice superior:
  21.                 Console.WriteLine (arregloEnteros[5].ToString());
  22.             }
  23.             catch (IndexOutOfRangeException ioore)
  24.             {
  25.                 Console.WriteLine ("Mensaje de error: `{0}`", ioore.Message);
  26.             }
  27.         }
  28.     }
  29. }