Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Last active August 29, 2015 14:04
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/d0d77c52a3b9e26a4d4b to your computer and use it in GitHub Desktop.
Save Fhernd/d0d77c52a3b9e26a4d4b to your computer and use it in GitHub Desktop.
Demostración del uso de la excepción InvalidOperationException en C#.
using System;
using System.IO;
namespace Articulos.Cap04.Excepciones.Parte5
{
public sealed class UsoInvalidOperationException
{
public static void Main()
{
// Apertura y creación del archivo.
StreamWriter sw = new StreamWriter("demo.txt");
sw.WriteLine("Blog");
sw.WriteLine("xCSw");
// Cierre del archivo:
sw.Close();
try
{
// Intento de agregar una nueva línea al archivo
// después de que el archivo fue cerrado:
sw.WriteLine ("OrtizOL");
}
catch (InvalidOperationException ioe)
{
Console.WriteLine ("Mensaje de error: `{0}`", ioe.Message);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment