8000 PythonTypeName property added to the PythonException object. by dmitriyse · Pull Request #597 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

PythonTypeName property added to the PythonException object. #597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
PythonTypeName property added to the PythonException object.
  • Loading branch information
dse committed Jan 13, 2018
commit c9afb7ad758d4bdfbe0f97aded491df3eda68f41
14 changes: 14 additions & 0 deletions src/embed_tests/TestPythonException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,19 @@ public void TestNoError()
var e = new PythonException(); // There is no PyErr to fetch
Assert.AreEqual("", e.Message);
}

[Test]
public void TestPythonErrorTypeName()
{
try
{
var module = PythonEngine.ImportModule("really____unknown___module");
Assert.Fail("Unknown module should not be loaded");
}
catch (PythonException ex)
{
Assert.AreEqual(ex.PythonTypeName, "ModuleNotFoundError");
}
}
}
}
10 changes: 10 additions & 0 deletions src/runtime/pythonexception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class PythonException : System.Exception
private IntPtr _pyTB = IntPtr.Zero;
private string _tb = "";
private string _message = "";
private string _pythonTypeName = "";
private bool disposed = false;

public PythonException()
Expand All @@ -33,6 +34,8 @@ public PythonException()
type = pyTypeName.ToString();
}

_pythonTypeName = type;

Runtime.XIncref(_pyValue);
using (var pyValue = new PyObject(_pyValue))
{
Expand Down Expand Up @@ -132,6 +135,13 @@ public override string StackTrace
get { return _tb; }
}

/// <summary>
/// Python error type name.
/// </summary>
public string PythonTypeName
{
get { return _pythonTypeName; }
}

/// <summary>
/// Dispose Method
Expand Down
0