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

Skip to content

Commit e9b22d9

Browse files
committed
Implement writing the __cause__ attribute on exceptions.
1 parent db9478f commit e9b22d9

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/runtime/clrobject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal CLRObject(Object ob, IntPtr tp) : base()
3232
inst = ob;
3333

3434
// Fix the BaseException args slot if wrapping a CLR exception
35-
Exceptions.SetArgs(py);
35+
Exceptions.SetArgsAndCause(py);
3636
}
3737

3838

src/runtime/exceptions.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ internal static void Shutdown()
144144
/// </summary>
145145
/// <param name="e">A CLR exception</param>
146146
/// <param name="ob">The python object wrapping </param>
147-
internal static void SetArgs(IntPtr ob)
147+
internal static void SetArgsAndCause(IntPtr ob)
148148
{
149149
var e = ExceptionClassObject.ToException(ob);
150150
if (e == null)
@@ -163,6 +163,15 @@ internal static void SetArgs(IntPtr ob)
163163
}
164164

165165
Marshal.WriteIntPtr(ob, ExceptionOffset.args, args);
166+
167+
#if !(PYTHON25 || PYTHON26 || PYTHON27)
168+
if (e.InnerException != null)
169+
{
170+
IntPtr cause = CLRObject.GetInstHandle(e.InnerException);
171+
Runtime.XIncref(cause);
172+
Marshal.WriteIntPtr(ob, ExceptionOffset.cause, cause);
173+
}
174+
#endif
166175
}
167176

168177
/// <summary>

0 commit comments

Comments
 (0)