File tree Expand file tree Collapse file tree 3 files changed +40
-2
lines changed
Expand file tree Collapse file tree 3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
2525
2626### Changed
2727
28+ - Reattach python exception traceback information (#545 )
29+
2830### Fixed
2931
3032- Fixed secondary PythonEngine.Initialize call, all sensitive static variables now reseted.
@@ -697,4 +699,4 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
697699[ i131 ] : https://github.com/pythonnet/pythonnet/issues/131
698700[ p531 ] : https://github.com/pythonnet/pythonnet/pull/531
699701[ i755 ] : https://github.com/pythonnet/pythonnet/pull/755
700- [ p534 ] : https://github.com/pythonnet/pythonnet/pull/534
702+ [ p534 ] : https://github.com/pythonnet/pythonnet/pull/534
Original file line number Diff line number Diff line change @@ -256,7 +256,10 @@ public static void SetError(Exception e)
256256 var pe = e as PythonException ;
257257 if ( pe != null )
258258 {
259- Runtime . PyErr_SetObject ( pe . PyType , pe . PyValue ) ;
259+ Runtime . XIncref ( pe . PyType ) ;
260+ Runtime . XIncref ( pe . PyValue ) ;
261+ Runtime . XIncref ( pe . PyTB ) ;
262+ Runtime . PyErr_Restore ( pe . PyType , pe . PyValue , pe . PyTB ) ;
260263 return ;
261264 }
262265
Original file line number Diff line number Diff line change @@ -128,6 +128,39 @@ def test_derived_class():
128128 assert id (x ) == id (ob )
129129
130130
131+ def test_derived_traceback ():
132+ """Test python exception traceback in class derived from managed base"""
133+ class DerivedClass (SubClassTest ):
134+ __namespace__ = "Python.Test.traceback"
135+
136+ def foo (self ):
137+ print (xyzname )
138+ return None
139+
140+ import sys ,traceback
141+ ob = DerivedClass ()
142+
143+ # direct call
144+ try :
145+ ob .foo ()
146+ assert False
147+ except :
148+ e = sys .exc_info ()
149+ assert "xyzname" in str (e [1 ])
150+ location = traceback .extract_tb (e [2 ])[- 1 ]
151+ assert location [2 ] == "foo"
152+
153+ # call through managed code
154+ try :
155+ FunctionsTest .test_foo (ob )
156+ assert False
157+ except :
158+ e = sys .exc_info ()
159+ assert "xyzname" in str (e [1 ])
160+ location = traceback .extract_tb (e [2 ])[- 1 ]
161+ assert location [2 ] == "foo"
162+
163+
131164def test_create_instance ():
132165 """Test derived instances can be created from managed code"""
133166 DerivedClass = derived_class_fixture (test_create_instance .__name__ )
You can’t perform that action at this time.
0 commit comments