Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-39041

Introduce QJSEngine throwError convenience method





      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+/QJS wrapped object that exposes properties, slots, etc. that could result in 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,


        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



            rweickelt Richard Weickelt
            thornto4 Ryan Thornton
            14 Vote for this issue
            20 Start watching this issue



                Gerrit Reviews

                There are no open Gerrit changes