Make exception handling use the new ScriptException class. Add exception signal Throw exceptions in script evaluation Remove references to ScriptManager from ScriptEngine
Showing the changes to libraries/script-engine/src/ScriptManager.cpp (1 of 8 files). Show all
Unified · Split
| @@ -284,10 +284,16 @@ ScriptManager::ScriptManager(Context context, const QString& scriptContents, con · 283 unmodified lines | |||
| 284 | 284 | ||
| 285 | // this is where all unhandled exceptions end up getting logged | 285 | // this is where all unhandled exceptions end up getting logged |
| 286 | connect(this, &ScriptManager::unhandledException, this, [this](const ScriptValue& err) { | 286 | connect(this, &ScriptManager::unhandledException, this, [this](const ScriptValue& err) { |
| 287 | qCCritical(scriptengine) << "Caught exception"; | ||
| 288 | |||
| 287 | auto output = err.engine() == _engine ? err : _engine->makeError(err); | 289 | auto output = err.engine() == _engine ? err : _engine->makeError(err); |
| 288 | if (!output.property("detail").isValid()) { | 290 | if (!output.property("detail").isValid()) { |
| 289 | output.setProperty("detail", "UnhandledException"); | 291 | output.setProperty("detail", "UnhandledException"); |
| 290 | } | 292 | } |
| 293 | |||
| 294 | // Unhandled exception kills the running script | ||
| 295 | stop(false); | ||
| 296 | |||
| 291 | logException(output); | 297 | logException(output); |
| 292 | }); | 298 | }); |
| 293 | 299 | ||
| @@ -886,6 +892,14 @@ void ScriptManager::run() { · 592 unmodified lines | |||
| 886 | PROFILE_RANGE(script, _fileNameString); | 892 | PROFILE_RANGE(script, _fileNameString); |
| 887 | _returnValue = _engine->evaluate(_scriptContents, _fileNameString); | 893 | _returnValue = _engine->evaluate(_scriptContents, _fileNameString); |
| 888 | _engine->maybeEmitUncaughtException(__FUNCTION__); | 894 | _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 | } | ||
| 889 | } | 903 | } |
| 890 | #ifdef _WIN32 | 904 | #ifdef _WIN32 |
| 891 | // VS13 does not sleep_until unless it uses the system_clock, see: | 905 | // VS13 does not sleep_until unless it uses the system_clock, see: |
| @@ -1008,7 +1022,7 @@ void ScriptManager::run() { · 116 unmodified lines | |||
| 1008 | // only clear exceptions if we are not in the middle of evaluating | 1022 | // only clear exceptions if we are not in the middle of evaluating |
| 1009 | if (!_engine->isEvaluating() && _engine->hasUncaughtException()) { | 1023 | if (!_engine->isEvaluating() && _engine->hasUncaughtException()) { |
| 1010 | qCWarning(scriptengine) << __FUNCTION__ << "---------- UNCAUGHT EXCEPTION --------"; | 1024 | qCWarning(scriptengine) << __FUNCTION__ << "---------- UNCAUGHT EXCEPTION --------"; |
| 1011 | qCWarning(scriptengine) << "runInThread" << _engine->uncaughtException().toString(); | 1025 | qCWarning(scriptengine) << "runInThread" << _engine->uncaughtException(); |
| 1012 | emit unhandledException(_engine->cloneUncaughtException(__FUNCTION__)); | 1026 | emit unhandledException(_engine->cloneUncaughtException(__FUNCTION__)); |
| 1013 | _engine->clearExceptions(); | 1027 | _engine->clearExceptions(); |
| 1014 | } | 1028 | } |