History

Initial exception handling

Make exception handling use the new ScriptException class. Add exception signal Throw exceptions in script evaluation Remove references to ScriptManager from ScriptEngine

Dale Glass committed 3 years ago

Commit c0e62c51 parent 2bcd1108 files · +297 −92Browse files

Showing the changes to libraries/script-engine/src/ScriptManager.cpp (1 of 8 files). Show all

Unified · Split

libraries/script-engine/src/ScriptManager.cpp+15−1
@@ -284,10 +284,16 @@ ScriptManager::ScriptManager(Context context, const QString& scriptContents, con · 283 unmodified lines
284284
285285 // this is where all unhandled exceptions end up getting logged
286286 connect(this, &ScriptManager::unhandledException, this, [this](const ScriptValue& err) {
287+ qCCritical(scriptengine) << "Caught exception";
288+
287289 auto output = err.engine() == _engine ? err : _engine->makeError(err);
288290 if (!output.property("detail").isValid()) {
289291 output.setProperty("detail", "UnhandledException");
290292 }
293+
294+ // Unhandled exception kills the running script
295+ stop(false);
296+
291297 logException(output);
292298 });
293299
@@ -886,6 +892,14 @@ void ScriptManager::run() { · 592 unmodified lines
886892 PROFILE_RANGE(script, _fileNameString);
887893 _returnValue = _engine->evaluate(_scriptContents, _fileNameString);
888894 _engine->maybeEmitUncaughtException(__FUNCTION__);
895+
896+ if (_engine->hasUncaughtException()) {
897+
898+ qCWarning(scriptengine) << "Engine has uncaught exception, stopping";
899+ stop();
900+ emit unhandledException(_engine->cloneUncaughtException(__FUNCTION__));
901+ _engine->clearExceptions();
902+ }
889903 }
890904 #ifdef _WIN32
891905 // VS13 does not sleep_until unless it uses the system_clock, see:
@@ -1008,7 +1022,7 @@ void ScriptManager::run() { · 116 unmodified lines
10081022 // only clear exceptions if we are not in the middle of evaluating
10091023 if (!_engine->isEvaluating() && _engine->hasUncaughtException()) {
10101024 qCWarning(scriptengine) << __FUNCTION__ << "---------- UNCAUGHT EXCEPTION --------";
1011− qCWarning(scriptengine) << "runInThread" << _engine->uncaughtException().toString();
1025+ qCWarning(scriptengine) << "runInThread" << _engine->uncaughtException();
10121026 emit unhandledException(_engine->cloneUncaughtException(__FUNCTION__));
10131027 _engine->clearExceptions();
10141028 }