diff --git a/src/runtime/pythonexception.cs b/src/runtime/pythonexception.cs index 0d0b2e3e6..552f004eb 100644 --- a/src/runtime/pythonexception.cs +++ b/src/runtime/pythonexception.cs @@ -35,17 +35,25 @@ public PythonException() : base() if ((_pyType != IntPtr.Zero) && (_pyValue != IntPtr.Zero)) { string type; + string message; + Runtime.Incref(_pyType); using (PyObject pyType = new PyObject(_pyType)) using (PyObject pyTypeName = pyType.GetAttr("__name__")) { type = pyTypeName.ToString(); } - string message = Runtime.GetManagedString(_pyValue); + + Runtime.Incref(_pyValue); + using (PyObject pyValue = new PyObject(_pyValue)) + { + message = pyValue.ToString(); + } _message = type + " : " + message; } if (_pyTB != IntPtr.Zero) { PyObject tb_module = PythonEngine.ImportModule("traceback"); + Runtime.Incref(_pyTB); using (PyObject pyTB = new PyObject(_pyTB)) { _tb = tb_module.InvokeMethod("format_tb", pyTB).ToString(); } @@ -99,6 +107,18 @@ public IntPtr PyValue get { return _pyValue; } } + /// + /// PyTB Property + /// + /// + /// + /// Returns the TraceBack as a Python object. + /// + + public IntPtr PyTB { + get { return _pyTB; } + } + /// /// Message Property ///