Skip to content

exception message thrown from python side is not transferrred to .net #82

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

Closed
den-run-ai opened this issue Jul 9, 2015 · 1 comment
Closed

Comments

@den-run-ai
Copy link
Contributor

If I have exception thrown in Python, e.g.

raise LookupError('the message is not passed to CSHARP')

then on .NET side it only shows:

((Python.Runtime.PythonException)$exception).Message
"LookupError : "
string

@den-run-ai
Copy link
Contributor Author

I found the problem in the code: IntPtr has to be converted to PyObject_Str() pointer instead of passing the original pointer to GetManagedString().

IntPtr _pyValueStr = PyObject_Str(_pyValue);
string message = Runtime.GetManagedString(_pyValueStr);

https://github.com/pythonnet/pythonnet/blob/master/src/runtime/pythonexception.cs#L38

I found the solution here:

http://stackoverflow.com/a/15907460/2230844

The reason why PyObject_Str() has to be called is because the original pointer is actually a TUPLE, not a string!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant