Advertisement
Fhernd

UsoInvalidOperationException.cs

Jul 28th, 2014
4,405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace Articulos.Cap04.Excepciones.Parte5
  5. {
  6.     public sealed class UsoInvalidOperationException
  7.     {
  8.         public static void Main()
  9.         {
  10.             // Apertura y creación del archivo.
  11.             StreamWriter sw = new StreamWriter("demo.txt");
  12.            
  13.             sw.WriteLine("Blog");
  14.             sw.WriteLine("xCSw");
  15.            
  16.             // Cierre del archivo:
  17.             sw.Close();
  18.            
  19.             try
  20.             {
  21.                 // Intento de agregar una nueva línea al archivo
  22.                 // después de que el archivo fue cerrado:
  23.                 sw.WriteLine ("OrtizOL");
  24.             }
  25.             catch (InvalidOperationException ioe)
  26.             {
  27.                 Console.WriteLine ("Mensaje de error: `{0}`", ioe.Message);
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement