Last active
August 29, 2015 14:04
-
-
Save Fhernd/d0d77c52a3b9e26a4d4b to your computer and use it in GitHub Desktop.
Demostración del uso de la excepción InvalidOperationException en C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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