I keep getting syntax errors with no line numbers as well.

That happens when I use Context.compileReader(..) to compile the script. The
DefaultErrorReporter will throw an exception with only the message and not the
line it happened on.

It is of course easy to workaround using your own error reporter, but I've
attached a patch to add on the line and source name so the DefaultErrorReporter
gives the similar output as EcmaError if that is wanted.
This commit is contained in:
nboyd%atg.com 2002-06-17 00:49:47 +00:00
Родитель a9bd55a1ce
Коммит 33086d8fc5
1 изменённых файлов: 17 добавлений и 2 удалений

Просмотреть файл

@ -48,16 +48,31 @@ class DefaultErrorReporter implements ErrorReporter {
// do nothing
}
private String generateErrorMessage(String message, String sourceName, int line) {
StringBuffer buf = new StringBuffer(message);
buf.append(" (");
if (sourceName != null) {
buf.append(sourceName);
buf.append("; ");
}
if (line > 0) {
buf.append("line ");
buf.append(line);
}
buf.append(')');
return buf.toString();
}
public void error(String message, String sourceName, int line,
String lineSource, int lineOffset)
{
throw new EvaluatorException(message);
throw new EvaluatorException(generateErrorMessage(message, sourceName, line));
}
public EvaluatorException runtimeError(String message, String sourceName,
int line, String lineSource,
int lineOffset)
{
return new EvaluatorException(message);
return new EvaluatorException(generateErrorMessage(message, sourceName, line));
}
}