using System; namespace Articulos.Excepciones.Parte4 { // Clase personalidad para registros de desbordamiento: public class TablaRegistroException : Exception { private const string mensajeDesbordamiento = "Se ha generado un desbordamiento de memoria."; public TablaRegistroException(string mensaje, Exception inner) : base (String.Format ("{0} - {1}", mensajeDesbordamiento, mensaje) , inner) { this.HelpLink = "http://o...content-available-to-author-only...t.com"; this.Source = "xCSw_Exceptiones"; } } public class TablaRegistro { protected int elementoActual; protected string[] registros; public TablaRegistro (int numeroElementos) { registros = new string [numeroElementos]; elementoActual = 0; } // Agrega un nuevo registro a la tabla: public int AgregarRegistro(string registro) { try { registros[elementoActual] = registro; return ++elementoActual; } catch (Exception e) { throw new TablaRegistroException ( String.Format("Registro `{0}` no fue agregado.", registro), e ); } } } public sealed class UsoTargetSite { public static void Main() { // Creación de la tabla de registros: TablaRegistro tr = new TablaRegistro(4); Console.WriteLine (String.Format ("\nDemostración del uso de las propiedades: \n\t`{0}`,\n\t`{1}`\n\t`{2}`\n\t`{3}`", "TargetSite", "HelpLink", "Source", "StackTrace") ); try { for (int i = 1; ; ++i) { tr.AgregarRegistro( String.Format ("Número de registro: {0}", i.ToString()) ); } } catch (Exception ex) { Console.WriteLine ("\nDatos de la excepción generada:"); Console.WriteLine ("\t`Mensaje`: {0}", ex.Message); Console.WriteLine ("\t`TargetSite`: {0}", ex.TargetSite); Console.WriteLine ("\t`HelpLink`: {0}", ex.HelpLink); Console.WriteLine ("\t`Source`: {0}", ex.Source); Console.WriteLine ("\t`StackTrace`: {0}", ex.StackTrace); } } } }