Created
July 18, 2014 22:52
-
-
Save Fhernd/d9d7a8ec4be88ab0f3ee to your computer and use it in GitHub Desktop.
Demostración del uso de la propiedad System.Exception.Data.
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.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 ("\nSe 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 ("\nDetalles adicionales de la excepción:"); | |
foreach (DictionaryEntry de in e.Data) | |
{ | |
Console.WriteLine ("\tLlave: {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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment