Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 79457fe

Browse files
committed
catch exceptions in tp_str when calling ToString.
1 parent 909a537 commit 79457fe

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pythonnet/src/runtime/classbase.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,17 @@ public static IntPtr tp_str(IntPtr ob) {
170170
if (co == null) {
171171
return Exceptions.RaiseTypeError("invalid object");
172172
}
173-
return Runtime.PyString_FromString(co.inst.ToString());
173+
try {
174+
return Runtime.PyString_FromString(co.inst.ToString());
175+
}
176+
catch (Exception e)
177+
{
178+
if (e.InnerException != null) {
179+
e = e.InnerException;
180+
}
181+
Exceptions.SetError(e);
182+
return IntPtr.Zero;
183+
}
174184
}
175185

176186

0 commit comments

Comments
 (0)