static void Main(string[] args) { ArchivoTexto a = new ArchivoTexto(); try { OtraClase x = new OtraClase(); x.MetodoDeInstancia(); }catch (Exception ex) { Console.WriteLine(ex.Message); Exception e = ex.InnerException; while (!object.ReferenceEquals(e, null)) { //Console.WriteLine(e.Message);//voy imprimiendo todas las excepciones ya entendi a.Guardar(AppDomain.CurrentDomain.BaseDirectory + (DateTime.Now.Year).ToString() + (DateTime.Now.Month).ToString() + (DateTime.Now.Day).ToString() + "-" + DateTime.Now.Hour.ToString() + DateTime.Now.Hour.ToString() + ".txt", e.Message); e = e.InnerException; } } Console.WriteLine(a.Leer(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + (DateTime.Now.Year).ToString() + (DateTime.Now.Month).ToString() + (DateTime.Now.Day).ToString() + "-" + DateTime.Now.Hour.ToString() + DateTime.Now.Hour.ToString() + ".txt")); //se rompe Console.ReadKey(); }
/// <summary> /// Modificar en el Main donde se captura la excepción. Quitar los Console.WriteLine y guardar /// todos los datos del error en un archivo de texto, cuyo nombre será la fecha y hora actual /// como indica este ejemplo: '20171012-1316.txt' (año mes día – hora minutos). /// </summary> /// <param name="args"></param> static void Main(string[] args) { DateTime dt = DateTime.Now; string filePath = dt.Year + dt.Month + dt.Day + "-" + dt.Hour + dt.Minute + ".txt"; try { C claseC = new C(); } catch (Exception e) { ArchivoTexto.Guardar(filePath, getTrace(e)); } Console.Write(ArchivoTexto.Leer(filePath)); Console.ReadKey(); }
static void Main(string[] args) { //Paso el path del escritorio de la máquina string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); //Agrego el formato requerido al nombre del archivo path = String.Format("{0}\\{1:yyyyMMdd-hhmm}.txt", path, DateTime.Now); try { OtraClase c = new OtraClase(); c.MiMetodoDeInstancia(); } catch (MiException e) { ArchivoTexto.Guardar(path, e.Message); if (!(e.InnerException is null)) { Exception excepcion = e.InnerException; do { ArchivoTexto.Guardar(path, excepcion.Message); excepcion = excepcion.InnerException; } while (!(object.ReferenceEquals(excepcion, null))); } } //path = "lala"; //Leo el archivo y muestro por pantalla try { Console.WriteLine(ArchivoTexto.Leer(path)); } catch (Exception exeptionArchivo) { Console.WriteLine(exeptionArchivo); } Console.ReadKey(); }
static void Main(string[] args) { try { ClaseException exception = new ClaseException(0); exception.mainException(); } catch (UnaExcepcion e) { string fecha = DateTime.Today.ToString(); ArchivoTexto.Guardar(String.Format("{0}.txt", fecha), e.Message); if (!(e.InnerException is null)) { //ArchivoTexto.Guardar(DateTime.Now.ToString(), e.InnerException.Message); } } Console.ReadKey(); }
static void Main(string[] args) { MiClase excepcion = new MiClase("hola"); //try //{ // excepcion.MiMetodo(); //} //catch(Exception e) //{ // Console.WriteLine(e.Message); // Console.WriteLine(e.InnerException.Message); // Console.WriteLine(e.InnerException.InnerException.Message); //} try { Console.WriteLine(ArchivoTexto.Leer("D:\\asdasdasd.txt")); } catch (FileNotFoundException e) { Console.WriteLine("EL archivo no existe"); } Console.ReadKey(); }