Skip to content

Commit 2450cce

Browse files
committed
chunk CreateSubType to locate crash more precisely
1 parent 08ea6f3 commit 2450cce

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/runtime/typemanager.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,18 +346,34 @@ internal static IntPtr CreateSubType(IntPtr py_name, IntPtr py_base_type, IntPtr
346346
return Exceptions.RaiseTypeError("invalid base class, expected CLR class type");
347347
}
348348

349+
Type subType;
349350
try
350351
{
351-
Type subType = ClassDerivedObject.CreateDerivedType(name,
352+
subType = ClassDerivedObject.CreateDerivedType(name,
352353
baseClass.type,
353354
py_dict,
354355
(string)namespaceStr,
355356
(string)assembly);
357+
}
358+
catch (Exception e)
359+
{
360+
return Exceptions.RaiseTypeError("Unable to generate derived type: " + e.Message);
361+
}
356362

363+
IntPtr py_type;
364+
try
365+
{
357366
// create the new ManagedType and python type
358367
ClassBase subClass = ClassManager.GetClass(subType);
359-
IntPtr py_type = GetTypeHandle(subClass, subType);
368+
py_type = GetTypeHandle(subClass, subType);
369+
}
370+
catch (Exception e)
371+
{
372+
return Exceptions.RaiseTypeError("Unable to reflect new .NET type to Python: " + e.Message);
373+
}
360374

375+
try
376+
{
361377
// by default the class dict will have all the C# methods in it, but as this is a
362378
// derived class we want the python overrides in there instead if they exist.
363379
IntPtr cls_dict = Marshal.ReadIntPtr(py_type, TypeOffset.tp_dict);
@@ -375,7 +391,7 @@ internal static IntPtr CreateSubType(IntPtr py_name, IntPtr py_base_type, IntPtr
375391
}
376392
catch (Exception e)
377393
{
378-
return Exceptions.RaiseTypeError(e.Message);
394+
return Exceptions.RaiseTypeError("Unable to update reflected type: " + e.Message);
379395
}
380396
}
381397

0 commit comments

Comments
 (0)