Position into script where runtime error occured?

How can I get line number and position + symbol which cause runtime error

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
class testc
{
public string ttt
{
get
{
return null;
}
}
}

class Program
{
    static void Main(string[] args)
    {
        using (var cmp = new RemObjects.Script.EcmaScriptComponent())
        {
            cmp.Debug = true;
            cmp.DebugException += cmp_DebugException;
            cmp.DebugExceptionUnwind += cmp_DebugExceptionUnwind;
            cmp.Globals.SetVariable("aa", new testc());

            cmp.Include("func", @"function myFunc() {

var a = aa.ttt;
a = a.substr(0,10);

}");

            try
            {
                cmp.RunFunction("myFunc");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }

    static void cmp_DebugExceptionUnwind(object sender, RemObjects.Script.ScriptDebugEventArgs e)
    {

    }

    static void cmp_DebugException(object sender, RemObjects.Script.ScriptDebugEventArgs e)
    {

    }
}

}

Hello.

You can get line number and position where error happens by adding the next code:

                . . .   
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    var row = cmp.DebugLastPos.StartRow;
                    var col = cmp.DebugLastPos.StartCol;
                }

Thanks

Hi there,

Is there some spacial (internal hidden) way to extract code which cause error or I need to do something like this

using RemObjects.Script;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
class Program
{
static string GetSymbol(PositionPair position, string code)
{
var symbol = string.Empty;
var start = position.Start;
var end = position.End;
var startLine = (start.Line - 1);
var endLine = (end.Line - 1);
var startColumn = start.Column - 1;
var endColumn = end.Column - 1;
var lines = code.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
if (startLine == endLine)
{
symbol = lines[startLine].Substring(startColumn, endColumn - startColumn - 1);
}
else
{
var text = new StringBuilder();
for (int i = startLine, l = endLine; i <= l; i++)
{
if (i == startLine)
{
text.AppendLine(lines[i].Substring(startColumn));
}
else
{
if (i == endLine)
{
text.Append(lines[i].Substring(0, endColumn - 1));
}
else
{
text.AppendLine(lines[i]);
}
}
}
symbol = text.ToString();
}
return symbol;
}

    static void Main(string[] args)
    {
        var script = @"function myFunc() {

var a=null;
a.substr(0,10);
}";

        using (var cmp = new RemObjects.Script.EcmaScriptComponent())
        {
            cmp.Debug = true;

            cmp.Include("myFuncInclude", script);

            var compiledScript = cmp.GlobalObject.InnerCompile(false, @"myFunc()");

            try
            {
                cmp.GlobalObject.InnerEval(false, compiledScript);
            }
            catch (Exception ex)
            {
                var symbol = GetSymbol(cmp.DebugLastPos, script);
                
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

}

Thanks