How to find the line number where an exception has occurred for embedded Python interpreter

Hi,

We have recently switched over our python implementation from IronPython to the embedded Python installation. Previously we were using the solution provided on this forum for finding the line number by calling Engine.GetService on the IronPython engine.

This doesn’t seem to work the same when using the embedded python implementation and when an exception occurs in our code during execution of the python script in RunFunction.

Is there a different way required for the embedded python?

Thanks

Hi Hamish,

I assume you’re using Alternet.Scripter.Python, right?

In case an exception occurs in the Python code, you can find the stack trace by examining the Exception.StackTrace property:

        try
        {
            scriptRun.Run();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.StackTrace);
        }

Please let me know if it works for you.

Regards,
Dmitry