From c1a9d9465936d096a7286775283861b4c8ab84f6 Mon Sep 17 00:00:00 2001 From: Danny Date: Tue, 11 Aug 2015 12:21:49 -0600 Subject: [PATCH 1/2] access to Exception Message and expose TraceBack property --- src/runtime/pythonexception.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/runtime/pythonexception.cs b/src/runtime/pythonexception.cs index 0d0b2e3e6..e939f2651 100644 --- a/src/runtime/pythonexception.cs +++ b/src/runtime/pythonexception.cs @@ -35,12 +35,19 @@ public PythonException() : base() if ((_pyType != IntPtr.Zero) && (_pyValue != IntPtr.Zero)) { string type; + string message; using (PyObject pyType = new PyObject(_pyType)) using (PyObject pyTypeName = pyType.GetAttr("__name__")) { type = pyTypeName.ToString(); } - string message = Runtime.GetManagedString(_pyValue); + + using (PyObject pyValue = new PyObject(_pyValue)) + { + message = pyValue.ToString(); + } + ; + _message = type + " : " + message; } if (_pyTB != IntPtr.Zero) @@ -99,6 +106,18 @@ public IntPtr PyValue get { return _pyValue; } } + /// + /// PyTB Property + /// + /// + /// + /// Returns the TraceBack as a Python object. + /// + + public IntPtr PyTB { + get { return _pyTB; } + } + /// /// Message Property /// From 7fc375dcac451175cb767bf4e59785ecbfa9a54a Mon Sep 17 00:00:00 2001 From: Danny Date: Fri, 14 Aug 2015 02:16:51 -0600 Subject: [PATCH 2/2] Added Runtime.Incref before using statements and removed uncessary semicolon --- src/runtime/pythonexception.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/runtime/pythonexception.cs b/src/runtime/pythonexception.cs index e939f2651..552f004eb 100644 --- a/src/runtime/pythonexception.cs +++ b/src/runtime/pythonexception.cs @@ -36,23 +36,24 @@ public PythonException() : base() { string type; string message; + Runtime.Incref(_pyType); using (PyObject pyType = new PyObject(_pyType)) using (PyObject pyTypeName = pyType.GetAttr("__name__")) { type = pyTypeName.ToString(); } - + + 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(); }