[runtime] Overwrite stacktrace for exception on re-throw. Fixes #1856.
if (mono_object_isinst (exc, mono_defaults.exception_class)) {
MonoException *mono_ex = (MonoException*)exc;
- if (!rethrow)
+ if (!rethrow) {
mono_ex->stack_trace = NULL;
+ mono_ex->trace_ips = NULL;
+ }
}
/* adjust eip so that it point into the call instruction */
if (mono_object_isinst (exc, mono_defaults.exception_class)) {
MonoException *mono_ex = (MonoException*)exc;
- if (!rethrow)
+ if (!rethrow) {
mono_ex->stack_trace = NULL;
+ mono_ex->trace_ips = NULL;
+ }
}
mono_handle_exception (&ctx, exc);
mono_restore_context (&ctx);
if (mono_object_isinst (exc, mono_defaults.exception_class)) {
MonoException *mono_ex = (MonoException*)exc;
- if (!rethrow)
+ if (!rethrow) {
mono_ex->stack_trace = NULL;
+ mono_ex->trace_ips = NULL;
+ }
}
res = unw_getcontext (&unw_ctx);
if (mono_object_isinst (exc, mono_defaults.exception_class)) {
MonoException *mono_ex = (MonoException*)exc;
- if (!rethrow)
+ if (!rethrow) {
mono_ex->stack_trace = NULL;
+ mono_ex->trace_ips = NULL;
+ }
}
mono_handle_exception (&ctx, exc);
#ifdef DEBUG_EXCEPTIONS
if (mono_object_isinst (exc, mono_defaults.exception_class)) {
MonoException *mono_ex = (MonoException*)exc;
- if (!rethrow)
+ if (!rethrow) {
mono_ex->stack_trace = NULL;
+ mono_ex->trace_ips = NULL;
+ }
}
mono_handle_exception (&ctx, exc);
mono_restore_context (&ctx);
if (mono_object_isinst (exc, mono_defaults.exception_class)) {
MonoException *mono_ex = (MonoException*)exc;
- if (!rethrow)
+ if (!rethrow) {
mono_ex->stack_trace = NULL;
+ mono_ex->trace_ips = NULL;
+ }
}
// mono_arch_handle_exception (&ctx, exc, FALSE);
mono_handle_exception (&ctx, exc);
if (mono_object_isinst (exc, mono_defaults.exception_class)) {
MonoException *mono_ex = (MonoException*)exc;
- if (!rethrow)
+ if (!rethrow) {
mono_ex->stack_trace = NULL;
+ mono_ex->trace_ips = NULL;
+ }
}
mono_handle_exception (&ctx, exc);
restore_context (&ctx);
if (mono_object_isinst (exc, mono_defaults.exception_class)) {
MonoException *mono_ex = (MonoException*)exc;
- if (!rethrow)
+ if (!rethrow) {
mono_ex->stack_trace = NULL;
+ mono_ex->trace_ips = NULL;
+ }
}
/* adjust eip so that it point into the call instruction */
exception15.cs \
exception16.cs \
exception17.cs \
+ exception18.cs \
typeload-unaligned.cs \
struct.cs \
valuetype-gettype.cs \
--- /dev/null
+using System;
+
+class C
+{
+ static Exception e;
+
+ static void Throw ()
+ {
+ try {
+ int.Parse (null);
+ } catch (Exception ex) {
+ e = ex;
+ }
+ }
+
+ static int FrameCount (Exception ex)
+ {
+ string fullTrace = ex.StackTrace;
+ string[] frames = fullTrace.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
+ return frames.Length;
+ }
+
+ public static void Main ()
+ {
+ Throw ();
+
+ try {
+ throw e;
+ } catch (Exception ex) {
+ int frames = FrameCount (ex);
+ if (frames != 1)
+ throw new Exception (String.Format("Exception carried {0} frames along with it when it should have reported one.", frames));
+ }
+
+ try {
+ try {
+ int.Parse (null);
+ } catch (Exception) {
+ throw;
+ }
+ } catch (Exception ex) {
+ int frames = FrameCount (ex);
+ if (frames != 4)
+ throw new Exception (String.Format("Exception carried {0} frames along with it when it should have reported four.", frames));
+ }
+
+ }
+}