Clear script engine errors once they have been reported

So that an error is not repeatedly reported to the console and log file.
Also consistently report filename.
And scripts included after one in error will now be run.
This commit is contained in:
David Rowe 2014-06-17 10:54:55 -07:00
parent 3b4ac91d60
commit e92ad86282

View file

@ -314,8 +314,9 @@ void ScriptEngine::evaluate() {
if (_engine.hasUncaughtException()) { if (_engine.hasUncaughtException()) {
int line = _engine.uncaughtExceptionLineNumber(); int line = _engine.uncaughtExceptionLineNumber();
qDebug() << "Uncaught exception at line" << line << ":" << result.toString(); qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString();
emit errorMessage("Uncaught exception at line" + QString::number(line) + ":" + result.toString()); emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + result.toString());
_engine.clearExceptions();
} }
} }
@ -324,7 +325,7 @@ QScriptValue ScriptEngine::evaluate(const QString& program, const QString& fileN
bool hasUncaughtException = _engine.hasUncaughtException(); bool hasUncaughtException = _engine.hasUncaughtException();
if (hasUncaughtException) { if (hasUncaughtException) {
int line = _engine.uncaughtExceptionLineNumber(); int line = _engine.uncaughtExceptionLineNumber();
qDebug() << "Uncaught exception at line" << line << ": " << result.toString(); qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ": " << result.toString();
} }
emit evaluationFinished(result, hasUncaughtException); emit evaluationFinished(result, hasUncaughtException);
_engine.clearExceptions(); _engine.clearExceptions();
@ -353,9 +354,9 @@ void ScriptEngine::run() {
QScriptValue result = _engine.evaluate(_scriptContents); QScriptValue result = _engine.evaluate(_scriptContents);
if (_engine.hasUncaughtException()) { if (_engine.hasUncaughtException()) {
int line = _engine.uncaughtExceptionLineNumber(); int line = _engine.uncaughtExceptionLineNumber();
qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString();
qDebug() << "Uncaught exception at line" << line << ":" << result.toString(); emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + result.toString());
emit errorMessage("Uncaught exception at line" + QString::number(line) + ":" + result.toString()); _engine.clearExceptions();
} }
QElapsedTimer startTime; QElapsedTimer startTime;
@ -495,8 +496,9 @@ void ScriptEngine::run() {
if (_engine.hasUncaughtException()) { if (_engine.hasUncaughtException()) {
int line = _engine.uncaughtExceptionLineNumber(); int line = _engine.uncaughtExceptionLineNumber();
qDebug() << "Uncaught exception at line" << line << ":" << _engine.uncaughtException().toString(); qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << _engine.uncaughtException().toString();
emit errorMessage("Uncaught exception at line" + QString::number(line) + ":" + _engine.uncaughtException().toString()); emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + _engine.uncaughtException().toString());
_engine.clearExceptions();
} }
} }
emit scriptEnding(); emit scriptEnding();
@ -656,5 +658,6 @@ void ScriptEngine::include(const QString& includeFile) {
int line = _engine.uncaughtExceptionLineNumber(); int line = _engine.uncaughtExceptionLineNumber();
qDebug() << "Uncaught exception at (" << includeFile << ") line" << line << ":" << result.toString(); qDebug() << "Uncaught exception at (" << includeFile << ") line" << line << ":" << result.toString();
emit errorMessage("Uncaught exception at (" + includeFile + ") line" + QString::number(line) + ":" + result.toString()); emit errorMessage("Uncaught exception at (" + includeFile + ") line" + QString::number(line) + ":" + result.toString());
_engine.clearExceptions();
} }
} }