Skip to content

PythonException.Format() throws another PythonException. #1190

Closed
@tetsushmz

Description

@tetsushmz

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'] .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions