}
}
- void AddFrames (StringBuilder sb, string newline, string unknown, StackTrace st) {
- for (int i = 0; i < st.FrameCount; i++) {
+ bool AddFrames (StringBuilder sb, string newline, string unknown, StackTrace st)
+ {
+ int i;
+ for (i = 0; i < st.FrameCount; i++) {
StackFrame frame = st.GetFrame (i);
if (i == 0)
sb.AppendFormat (" {0} ", Locale.GetText ("at"));
frame.GetFileLineNumber ());
}
}
+
+ return i != 0;
}
public virtual string StackTrace {
// Add traces captured using ExceptionDispatchInfo
if (captured_traces != null) {
foreach (var t in captured_traces) {
- AddFrames (sb, newline, unknown, t);
+ if (!AddFrames (sb, newline, unknown, t))
+ continue;
+
sb.Append (Environment.NewLine);
sb.Append ("--- End of stack trace from previous location where exception was thrown ---");
sb.Append (Environment.NewLine);
}
// For ExceptionDispatchInfo
- internal void CaptureTrace () {
+ internal void CaptureTrace ()
+ {
if (captured_traces != null) {
- StackTrace[] new_traces = new StackTrace [captured_traces.Length + 1];
- Array.Copy (captured_traces, new_traces, captured_traces.Length);
- captured_traces = new_traces;
+ Array.Resize (ref captured_traces, captured_traces.Length + 1);
} else {
captured_traces = new StackTrace [1];
}
var orig_stack = orig.StackTrace;
try {
ed.Throw ();
+ Assert.Fail ("#0");
} catch (Exception e) {
var s = e.StackTrace.Split ('\n');
Assert.AreEqual (4, s.Length, "#1");
}
}
+ [Test]
+ public void ThrowWithEmptyFrames ()
+ {
+ var edi = ExceptionDispatchInfo.Capture (new OperationCanceledException ());
+ try {
+ edi.Throw ();
+ Assert.Fail ("#0");
+ } catch (OperationCanceledException e) {
+ Assert.IsFalse (e.StackTrace.Contains ("---"));
+ }
+ }
+
}
}