I'm trying to get which line is generating an error when calling a kotlin script from java.
The following code gives line number -1.
try
{
String scriptcode = "\n\nthrow Exception()";
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByExtension("kts");
engine.eval(scriptcode);
}
catch(ScriptException se)
{
System.out.println(se.getLineNumber());
}
Am I missing something?
Could please try something like this. se.getStackTrace()[0].getLineNumber();