Since QtScript is being deprecated, I've been attempting to write an event driven scriptable monitoring framework in Qt5 with the QJS family of classes and I've ran into one annoying problem.
QJSEngine, QJSValue, etc. lack the ability to induce a thrown exception in script code similar to QScriptContext::throwError(...) from C++ calls for QJS wrapped objects.
As far as I can tell, any injected C++ exceptions being thrown must wrap their return values and the resulting script code must unwrap the results using calls like isError(), isPending(), isValid(), etc. sprinkled all over my scripting code.
Instead of thrown C++ errors returning an Error object to QJSEngine, which usually results in attempting to call a non-existent property and the script crashing, It'd be nice for QJSEngine to automatically throw a received Error object that way I don't have to write yet another wrapper layer to do this for me.
In my framework, I'd like to be able to throw an error from my C++ classes, have it bubble up through the QJSEngine, make QJSEngine::evaluate(program) return with an error, and allow me to check the resulting Error object to determine whether or not it's an error I can safely ignore (due to a task or event not arriving yet ... but will sometime in the future) and one that I simply cannot (syntax error, invalid parameter, etc.).
Is there any plan for introducing similar functionality to QScriptContext::throwError into the QJS* family? If not what is the intended means or pattern for injecting errors back into script code?
Thanks and Kind Regards,
|For Gerrit Dashboard: QTBUG-39041|
|233390,4||Add QJSEngine::throwError() method to report run-time errors||dev||qt/qtdeclarative||Status: MERGED||+2||0|