try / catch und Ausnahmebehandlung..
-
Hallo,
eine Frage habe an Community. Ich habe mich schon tot abgesucht.
Gibts eine möglichkeit neben alle Fehler per:
catch (Exception ex) { MessageBox.Show("Format Fehler: " + ex.Message) }
auch Fehler ort oder in welche reihe es passiert ist auszugeben?
Die Exception list hilft nicht wirklich weiter.....somit frage ich mich ob es überhaupt möglich ist...
-
ex.StackTrace is your friend.
-
Kleine Helfermethode:
//Aufruf: getExceptionMessages(myException, 1) public static string getExceptionMessages(Exception ex, int level) { if (ex == null) return ""; StringBuilder builder = new StringBuilder(); string nl = Environment.NewLine; builder.Append(string.Format("{0}{0}------------Level {1}------------{0}{0}", nl, level)); builder.Append(string.Format("->Exception Type: {1}{0}{0}", nl, ex.GetType().FullName)); if (!string.IsNullOrEmpty(ex.Message)) builder.Append(string.Format("->Message: {1}{0}{0}", nl, ex.Message)); if (ex.TargetSite != null) builder.Append(string.Format("->TargetSite: {1}{0}{0}", nl, ex.TargetSite)); if (!string.IsNullOrEmpty(ex.Source)) builder.Append(string.Format("->Source: {1}{0}{0}", nl, ex.Source)); if (!string.IsNullOrEmpty(ex.StackTrace)) builder.Append(string.Format("->StackTrace: {0}{1}{0}{0}", nl, ex.StackTrace)); if (ex.Data != null && ex.Data.Count > 0) { builder.Append(string.Format("->Data:{0}", nl)); foreach (object x in ex.Data.Keys) { builder.Append(string.Format("Key {1}, Value {2}{0}", nl, x, ex.Data[x])); } } if (ex.InnerException != null) builder.Append(getExceptionMessages(ex.InnerException, level + 1)); return builder.ToString(); }
-
Firefighter schrieb:
ex.StackTrace is your friend.
Hallo Firefighter!
Du bist der Größte