Add logging of signal slot exceptions in ScriptEngine
Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all
Unified · Split
| @@ -51,6 +51,8 @@ · 50 unmodified lines | ||
| 51 | 51 | |
| 52 | 52 | #include "MIDIEvent.h" |
| 53 | 53 | |
| 54 | +static const QString SCRIPT_EXCEPTION_FORMAT = "[UncaughtException] %1 in %2:%3"; | |
| 55 | + | |
| 54 | 56 | Q_DECLARE_METATYPE(QScriptEngine::FunctionSignature) |
| 55 | 57 | static int functionSignatureMetaID = qRegisterMetaType<QScriptEngine::FunctionSignature>(); |
| 56 | 58 | |
| @@ -112,7 +114,7 @@ static bool hadUncaughtExceptions(QScriptEngine& engine, const QString& fileName · 55 unmodified lines | ||
| 112 | 114 | const auto line = QString::number(engine.uncaughtExceptionLineNumber()); |
| 113 | 115 | engine.clearExceptions(); |
| 114 | 116 | |
| 115 | − auto message = QString("[UncaughtException] %1 in %2:%3").arg(exception, fileName, line); | |
| 117 | + auto message = QString(SCRIPT_EXCEPTION_FORMAT).arg(exception, fileName, line); | |
| 116 | 118 | if (!backtrace.empty()) { |
| 117 | 119 | static const auto lineSeparator = "\n "; |
| 118 | 120 | message += QString("\n[Backtrace]%1%2").arg(lineSeparator, backtrace.join(lineSeparator)); |
| @@ -133,6 +135,10 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam · 14 unmodified lines | ||
| 133 | 135 | _allScriptsMutex.lock(); |
| 134 | 136 | _allKnownScriptEngines.insert(this); |
| 135 | 137 | _allScriptsMutex.unlock(); |
| 138 | + | |
| 139 | + connect(this, &QScriptEngine::signalHandlerException, this, [this](const QScriptValue& exception) { | |
| 140 | + hadUncaughtExceptions(*this, _fileNameString); | |
| 141 | + }); | |
| 136 | 142 | } |
| 137 | 143 | |
| 138 | 144 | ScriptEngine::~ScriptEngine() { |