# How to retrieve code line number and column number in python script code for sciptrun execution exception?

**URL:** https://forum.alternetsoft.com/t/how-to-retrieve-code-line-number-and-column-number-in-python-script-code-for-sciptrun-execution-exception/272
**Category:** AlterNET Studio Support
**Tags:** scripter, python
**Created:** [December 9, 2021, 11:37pm UTC](https://forum.alternetsoft.com/t/how-to-retrieve-code-line-number-and-column-number-in-python-script-code-for-sciptrun-execution-exception/272 "2021-12-09T23:37:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![audrius](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/a/606060/32.png) [@audrius](https://forum.alternetsoft.com/u/audrius)
#### Post date: [December 9, 2021, 11:37pm UTC](https://forum.alternetsoft.com/t/how-to-retrieve-code-line-number-and-column-number-in-python-script-code-for-sciptrun-execution-exception/272/1 "2021-12-09T23:37:25Z")

</div>

It would even be nice to retrieve “responsible code text”; As several instructions can be in one line separated by “;”  
Now I get smth like this:  
Attempted to divide by zero. at Microsoft.Scripting.Utils.MathUtils.FloorDivideUnchecked(Int32 x, Int32 y)  
at IronPython.Runtime.Operations.Int32Ops.FloorDivide(Int32 x, Int32 y)  
at IronPython.Runtime.Binding.PythonBinaryOperationBinder.IntDivide(CallSite site, Object self, Object other)  
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)  
at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)  
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)  
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)  
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)  
at IronPython.Compiler.PythonScriptCode.Run(Scope scope)  
at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)  
at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)  
at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)  
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)  
at Microsoft.Scripting.Hosting.ScriptEngine.Execute(String expression, ScriptScope scope)  
at Alternet.Scripter.IronPython.InMemoryRunnableScript.Execute(ScriptEngine engine, ScriptScope scope)  
at Alternet.Scripter.IronPython.IronPythonScriptHost.ExecuteAllScripts()  
at Alternet.Scripter.IronPython.IronPythonScriptHost.RunCore()  
at Alternet.Scripter.IronPython.ScriptHost.InternalRun()  
at Alternet.Scripter.IronPython.ScriptHost.Run()  
at Alternet.Scripter.IronPython.ScriptRun.Run()  
at PythonAndCSharpScripting.ViewModelBase.RunUserScript() in …

---

<div class="post-metadata">

### Author: ![andrew.medvedev](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/andrew.medvedev/32/28_2.png) [@andrew.medvedev](https://forum.alternetsoft.com/u/andrew.medvedev)
#### Post date: [December 10, 2021, 8:57am UTC](https://forum.alternetsoft.com/t/how-to-retrieve-code-line-number-and-column-number-in-python-script-code-for-sciptrun-execution-exception/272/2 "2021-12-10T08:57:34Z")

</div>

Hi audrius,

Could you please try to call Engine.GetService to get more details about exception in the exception catch block like this:

```auto
            try
            {
                scriptRun.RunFunction("OnPaint", new object[] { e.Graphics, displayPanel.ClientRectangle, currentAngle });
            }
            catch (Exception ex)
            {
                var trace = ((Alternet.Scripter.IronPython.IronPythonScriptHost)scriptRun.ScriptHost).Engine.GetService<Microsoft.Scripting.Hosting.ExceptionOperations>().FormatException(ex);

                MessageBox.Show(this, ex.Message, "Script Execution Error");
                StopScript();
            }

```

Where trace will contain information in such form:  
Traceback (most recent call last):  
File “”, line 1, in   
File “”, line 10, in OnPaint  
ZeroDivisionError: Attempted to divide by zero.

Regards,  
Andrew
