Skip to content

PythonException.Format() throws another PythonException. #1190

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
tetsushmz opened this issue Jul 25, 2020 · 0 comments
Closed

PythonException.Format() throws another PythonException. #1190

tetsushmz opened this issue Jul 25, 2020 · 0 comments

Comments

@tetsushmz
Copy link

tetsushmz commented Jul 25, 2020

Environment

  • Pythonnet version: V2.5.1.
  • Python version: V3.8.4 64 bit
  • Operating System: Windows 10 64 bit

Details

  1. Run the following code in a console application with Visual Studio.
using (Py.GIL())
{

    var script = "a=b\n";
    try
    {
        PythonEngine.Exec(script);
    }
    catch (PythonException ex)
    {
        try
        {
            var m = ex.Format();
        }
        catch (Exception exception)
        {
            var t = exception.GetType();
            var s = exception.Message;
        }
    }
}

Since "a=b" is invalid, I expected an error message like so returned by ex.Format():

Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'b' is not defined

However, Format() throws another PythonException - "AttributeError : 'str' object has no attribute 'cause'" with the following stack trace - list(TracebackException(\n', ' File "C:\Python38\Lib\traceback.py", line 479, in init\n if (exc_value and exc_value.cause is not None\n'] .

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