Advertisement
Fhernd

UsoTargetSite.cs

Jul 18th, 2014
2,088
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.62 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Articulos.Excepciones.Parte4
  4. {
  5.     // Clase personalidad para registros de desbordamiento:
  6.     public class TablaRegistroException : Exception
  7.     {
  8.         private const string mensajeDesbordamiento =
  9.             "Se ha generado un desbordamiento de memoria.";
  10.            
  11.         public TablaRegistroException(string mensaje, Exception inner) :
  12.             base (String.Format ("{0} - {1}",
  13.                     mensajeDesbordamiento, mensaje) , inner)
  14.         {
  15.             this.HelpLink = "http://ortizol.blogspot.com";
  16.             this.Source = "xCSw_Exceptiones";
  17.         }
  18.     }
  19.    
  20.     public class TablaRegistro
  21.     {
  22.         protected int elementoActual;
  23.         protected string[] registros;
  24.        
  25.         public TablaRegistro (int numeroElementos)
  26.         {
  27.             registros = new string [numeroElementos];
  28.             elementoActual = 0;
  29.         }
  30.        
  31.         // Agrega un nuevo registro a la tabla:
  32.         public int AgregarRegistro(string registro)
  33.         {
  34.             try
  35.             {
  36.                 registros[elementoActual] = registro;
  37.                 return ++elementoActual;
  38.             }
  39.             catch (Exception e)
  40.             {
  41.                 throw new TablaRegistroException (
  42.                     String.Format("Registro `{0}` no fue agregado.",
  43.                     registro), e
  44.                 );
  45.             }
  46.         }
  47.     }
  48.    
  49.     public sealed class UsoTargetSite
  50.     {
  51.         public static void Main()
  52.         {
  53.             // Creación de la tabla de registros:
  54.             TablaRegistro tr = new TablaRegistro(4);
  55.            
  56.             Console.WriteLine (String.Format ("\nDemostración del uso de las propiedades: \n\t`{0}`,\n\t`{1}`\n\t`{2}`\n\t`{3}`",
  57.                 "TargetSite", "HelpLink", "Source", "StackTrace")
  58.             );
  59.            
  60.             try
  61.             {
  62.                 for (int i = 1; ; ++i)
  63.                 {
  64.                     tr.AgregarRegistro(
  65.                         String.Format ("Número de registro: {0}", i.ToString())
  66.                     );
  67.                 }
  68.             }
  69.             catch (Exception ex)
  70.             {
  71.                 Console.WriteLine ("\nDatos de la excepción generada:");
  72.                 Console.WriteLine ("\t`Mensaje`: {0}", ex.Message);
  73.                 Console.WriteLine ("\t`TargetSite`: {0}", ex.TargetSite);
  74.                 Console.WriteLine ("\t`HelpLink`: {0}", ex.HelpLink);
  75.                 Console.WriteLine ("\t`Source`: {0}", ex.Source);
  76.                 Console.WriteLine ("\t`StackTrace`: {0}", ex.StackTrace);
  77.             }
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement