Our application hosts the Windows Scripting Host JScript engine and exposes several domain objects that can be called from script code.
One of the domain objects is a COM component that implements IDispatch (actually, IDispatchEx) and which has a method that takes a script-function as a call-back parameter (an IDispatch* as a parameter). This COM component is called by script, does some things, and then calls back into script via that supplied IDispatch parameter before returning to the calling script.
If the call-back script happens to throw an exception (e.g., makes a call to another COM component which returns something other than S_OK), then the call to IDispatch::Invoke on the call-back script will return SCRIPT_E_PROPAGATE instead of the HRESULT from the other COM component; not the expected HRESULT from the other COM object. If I return that HRESULT (SCRIPT_E_PROPAGATE) back to the caller of the first COM component (e.g., to the calling script), then the script engine correctly throws an error with the expected HRESULT from the other COM object.
However, the ACTUAL ERROR is nowhere to be found. It's not returned from the Invoke call (the return value is SCRIPT_E_PROPAGATE). It's not returned via the EXCEPINFO supplied to Invoke (the structure remains empty). AND, it's not available via GetErrorInfo (the call returns S_FALSE)!
Script
Defines ScriptCallback = function() { return ComComponentB.doSomething(); }
Invokes ComComponentA.execute(ScriptCallback)
Invokes ScriptCallback()
Invokes ComComponentB.doSomething()
Returns E_FAIL (or some other HRESULT)
Throws returned HRESULT
Receives SCRIPT_E_PROPAGATE <--- WHERE IS THE ACTUAL ERROR?
Returns SCRIPT_E_PROPAGATE
Throws E_FAIL (or whatever HRESULT was returned from ComComponentB)
I'd really like to get my hands on that error, because it would be useful to cache it and return the same error on subsequent calls (getting to the error often involves an expensive operation that is defined by the script-function passed as a parameter, but I do know how to cache the error). Is there a way for a scripted COM component to get to an exception thrown during a call-back into a supplied script-function???