Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 895403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:33:10+00:00 2026-05-15T14:33:10+00:00

Our application hosts the Windows Scripting Host JScript engine and exposes several domain objects

  • 0

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???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:33:10+00:00Added an answer on May 15, 2026 at 2:33 pm

    Wow, this was seriously underdocumented.

    The answer is to:

    In the COM component making a callback into script…

    1. QI to get an IDispatchEx pointer on the script function to be called.
    2. Construct an object implementing both IServiceProvider & ICanHandleException; e.g. CScriptErrorCapturer.
      • IServiceProvider::QueryService can return E_NOINTERFACE
      • If the script callback function throws, but does not catch, an exception when InvokEx’d (see below), then ICanHandleException::CanHandleException will get an EXCEPINFO and VARIANT* (look on MSDN for documentation).
      • The variant will contain the object thrown, which might be an Error object.
      • Try to get the “number” and “message” properties from the IDispatch on this Error object, where “number” represents the actual script error (HRESULT).
      • These values can/should be used to update the EXCEPINFO scode and (optionally) bstrDescription in order to propagate the error up to the calling script. If you don’t update the scode, then then engine will throw an “Exception thrown but not caught” (0x800A139E), which is what the EXCEPINFO contains before you modify it.
      • Not sure if pfnDeferredFillIn should be cleared, but it works without doing this.
      • In my code, I capture the error here in my CScriptErrorCapturer.
      • Return S_OK. Returning E_FAIL here will abort the entire script run, and not allow the exception to be thrown back up to the original calling script.
    3. Call IDispatchEx::InvokeEx and pass your CScriptErrorCapturer as the IServiceProvider parameter.
    4. Upon return from InvokeEx, query your CScriptErrorCapturer to see if it caught an error. According to code in the GoogleWebKit, sometimes InvokeEx may return S_OK, even if an error is thrown.
    5. Don’t touch the return value from InvokeEx, especially if it is SCRIPT_E_PROPAGATE (0x80020102)

    Note: this link contains some of the undocumented JScript HRESULTS described above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an application that uses several out of process COM objects for various
We are using Windows Azure Web Roles to host our MVC 3 application. From
Our application is a Java-GWT application that uses Guice-Persist and Guice-Servlet extensively. We have
Our application has many controls that are created dynamically. For example, a navigation pane
Our C++ application hosts Sun's JVM and I need to upgrade it to the
We host a C++ based WebServices application in IIS and we're finding that when
I have a WCF service that is hosted in a windows application. The service
We built a .NET server application that hosts data (contacts, email, etc.). We'd like
I have an server application (running as a Windows Service) that receives calls from
We have a Win32 application that hosts the .NET runtime and opens up .NET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.