Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 29, 2014 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/b51e8018c38ec0c8a38f to your computer and use it in GitHub Desktop.
Save Fhernd/b51e8018c38ec0c8a38f to your computer and use it in GitHub Desktop.
Demostración del uso de la excepción IndexOutOfRangeException en C#.
using System;
namespace Articulos.Cap04.Excepciones.Parte5
{
public sealed class UsoIndexOutOfRangeException
{
public static void Main()
{
int[] arregloEnteros = new int[5];
// Agrega 5 elementos al arreglo:
for (int i = 0; i < arregloEnteros.Length; ++i)
{
arregloEnteros[i] = i + 1;
}
try
{
// Intengo de acceder a un elemento del
// arreglo con un índice superior:
Console.WriteLine (arregloEnteros[5].ToString());
}
catch (IndexOutOfRangeException ioore)
{
Console.WriteLine ("Mensaje de error: `{0}`", ioore.Message);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment