Permalink
Browse files

Wrap thrown objects which do not derive from Exception into a Runtime…

…WrappedException. Fixes #640687.
  • Loading branch information...
1 parent 2faabf8 commit e4cb5aec35297fa6c59973ce14bf5b630f48b545 @vargaz vargaz committed Sep 23, 2010
Showing with 28 additions and 5 deletions.
  1. +11 −0 mono/metadata/exception.c
  2. +3 −0 mono/metadata/exception.h
  3. +5 −0 mono/metadata/object-internals.h
  4. +9 −5 mono/mini/mini-exceptions.c
View
@@ -749,3 +749,14 @@ mono_get_exception_reflection_type_load (MonoArray *types, MonoArray *exceptions
return (MonoException *) exc;
}
+
+MonoException *
+mono_get_exception_runtime_wrapped (MonoObject *wrapped_exception)
+{
+ MonoRuntimeWrappedException *ex = (MonoRuntimeWrappedException*)
+ mono_exception_from_name (mono_get_corlib (), "System.Runtime.CompilerServices",
+ "RuntimeWrappedException");
+
+ MONO_OBJECT_SETREF (ex, wrapped_exception, wrapped_exception);
+ return (MonoException*)ex;
+}
@@ -142,6 +142,9 @@ mono_get_exception_method_access (void);
MonoException *
mono_get_exception_reflection_type_load (MonoArray *types, MonoArray *exceptions);
+MonoException *
+mono_get_exception_runtime_wrapped (MonoObject *wrapped_exception);
+
MONO_END_DECLS
#endif /* _MONO_METADATA_EXCEPTION_H_ */
@@ -258,6 +258,11 @@ typedef struct {
MonoString *type_name;
} MonoTypeLoadException;
+typedef struct {
+ MonoException base;
+ MonoObject *wrapped_exception;
+} MonoRuntimeWrappedException;
+
typedef struct {
MonoObject object;
MonoObject *async_state;
@@ -1162,13 +1162,17 @@ mono_handle_exception_internal (MonoContext *ctx, gpointer obj, gpointer origina
obj = mono_get_exception_null_reference ();
}
- if (mono_object_isinst (obj, mono_defaults.exception_class)) {
- mono_ex = (MonoException*)obj;
- initial_trace_ips = mono_ex->trace_ips;
- } else {
- mono_ex = NULL;
+ if (!mono_object_isinst (obj, mono_defaults.exception_class)) {
+ obj = mono_get_exception_runtime_wrapped (obj);
+ /*
+ * FIXME: Might have to unwrap this before passing it to a catch clause based on the
+ * RuntimeCompatibilityAttribute.
+ */
}
+ mono_ex = (MonoException*)obj;
+ initial_trace_ips = mono_ex->trace_ips;
+
if (mono_ex && jit_tls->class_cast_from && !strcmp (mono_ex->object.vtable->klass->name, "InvalidCastException")) {
char *from_name = mono_type_get_full_name (jit_tls->class_cast_from);
char *to_name = mono_type_get_full_name (jit_tls->class_cast_to);

0 comments on commit e4cb5ae

Please sign in to comment.