using System;
using System.Collections ;
namespace Articulos.Excepciones .Parte4
{
public sealed class UsoData
{
public static void Main( )
{
UsarPropiedadData( ) ;
}
public static void UsarPropiedadData( )
{
try
{
GenerarExcepcion( ) ;
}
catch ( Exception e)
{
Console.WriteLine ( "\n Se ha generado una excepción." ) ;
Console.WriteLine ( "\t {0}" , e.Message ) ;
// Valida que la propiedad Data contiene elementos:
if ( e.Data .Count > 0 )
{
Console.WriteLine ( "\n Detalles adicionales de la excepción:" ) ;
foreach ( DictionaryEntry de in e.Data )
{
Console.WriteLine ( "\t Llave: {0,-20}Valor: {1}" ,
de.Key .ToString ( ) ,
de.Value .ToString ( )
) ;
}
Console.WriteLine ( ) ;
}
}
}
public static void GenerarExcepcion( )
{
Exception e = new Exception( ) ;
DateTime fechaHora = DateTime.Now ;
string mensaje = "Excepción generada en el método GenerarExcepcion." ;
int codigo = 852963741 ;
// Agrega pares llave/valor a la propiedad Data:
e.Data [ "ID" ] = codigo;
e.Data [ "FechaHora" ] = fechaHora;
e.Data [ "Mensaje" ] = mensaje;
throw e;
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnM7CgpuYW1lc3BhY2UgQXJ0aWN1bG9zLkV4Y2VwY2lvbmVzLlBhcnRlNAp7CiAgICBwdWJsaWMgc2VhbGVkIGNsYXNzIFVzb0RhdGEKICAgIHsKICAgICAgICBwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCiAgICAgICAgewogICAgICAgICAgICBVc2FyUHJvcGllZGFkRGF0YSgpOwogICAgICAgIH0KICAgICAgICAKICAgICAgICBwdWJsaWMgc3RhdGljIHZvaWQgVXNhclByb3BpZWRhZERhdGEoKQogICAgICAgIHsKICAgICAgICAgICAgdHJ5CiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIEdlbmVyYXJFeGNlcGNpb24oKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBjYXRjaCAoRXhjZXB0aW9uIGUpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lICgiXG5TZSBoYSBnZW5lcmFkbyB1bmEgZXhjZXBjacOzbi4iKTsKICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lICgiXHR7MH0iLCBlLk1lc3NhZ2UpOwogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAvLyBWYWxpZGEgcXVlIGxhIHByb3BpZWRhZCBEYXRhIGNvbnRpZW5lIGVsZW1lbnRvczoKICAgICAgICAgICAgICAgIGlmIChlLkRhdGEuQ291bnQgPiAwKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lICgiXG5EZXRhbGxlcyBhZGljaW9uYWxlcyBkZSBsYSBleGNlcGNpw7NuOiIpOwogICAgICAgICAgICAgICAgICAgIGZvcmVhY2ggKERpY3Rpb25hcnlFbnRyeSBkZSBpbiBlLkRhdGEpCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSAoIlx0TGxhdmU6IHswLC0yMH1WYWxvcjogezF9IiwgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZS5LZXkuVG9TdHJpbmcoKSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRlLlZhbHVlLlRvU3RyaW5nKCkKICAgICAgICAgICAgICAgICAgICAgICAgKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAKICAgICAgICBwdWJsaWMgc3RhdGljIHZvaWQgR2VuZXJhckV4Y2VwY2lvbigpCiAgICAgICAgewogICAgICAgICAgICBFeGNlcHRpb24gZSA9IG5ldyBFeGNlcHRpb24oKTsKICAgICAgICAgICAgCiAgICAgICAgICAgIERhdGVUaW1lIGZlY2hhSG9yYSA9IERhdGVUaW1lLk5vdzsKICAgICAgICAgICAgc3RyaW5nIG1lbnNhamUgPSAiRXhjZXBjacOzbiBnZW5lcmFkYSBlbiBlbCBtw6l0b2RvIEdlbmVyYXJFeGNlcGNpb24uIjsKICAgICAgICAgICAgaW50IGNvZGlnbyA9IDg1Mjk2Mzc0MTsKICAgICAgICAgICAgCiAgICAgICAgICAgIC8vIEFncmVnYSBwYXJlcyBsbGF2ZS92YWxvciBhIGxhIHByb3BpZWRhZCBEYXRhOgogICAgICAgICAgICBlLkRhdGFbIklEIl0gPSBjb2RpZ287CiAgICAgICAgICAgIGUuRGF0YVsiRmVjaGFIb3JhIl0gPSBmZWNoYUhvcmE7CiAgICAgICAgICAgIGUuRGF0YVsiTWVuc2FqZSJdID0gbWVuc2FqZTsKICAgICAgICAgICAgCiAgICAgICAgICAgIHRocm93IGU7CiAgICAgICAgfQogICAgfQp9