Article ID: 232394 - View products that this article applies to.
This article was previously published under Q232394
This article has been archived. It is offered "as is" and will no longer be updated.
Note Microsoft Visual C++ 2005, Microsoft Visual C++ .NET 2003, and Microsoft Visual C++ .NET 2002 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code.
Like all programs, scripts running in an ActiveX Script Host can throw two kinds of errors, compile-time and run-time. In earlier implementations, the ActiveX Scripting Engines provided by Microsoft (VBScript and JScript), made no distinction between the two types of errors. Both were handled in IActiveScriptSite::OnScriptError(). With more recent versions of the script engines, a distinction was made between run-time and compile-time errors. Compile-time errors, such as syntax errors, are still reported to the ActiveX Script Host using the IActiveScriptSite::OnScriptError() method. However, run-time errors, such as passing invalid arguments, are not directly reported to OnScriptError(). Instead, they are reported to a different method, IActiveScriptSiteDebug::OnScriptErrorDebug().
This article describes how to modify an existing ActiveX Script Host to catch run-time errors thrown from scripts.
This article assumes that you've already written an ActiveX Script Host. For more information on doing this, please see the articles noted in the "References" section of this article.
In the newest releases of the script engines, IActiveScriptSiteDebug::OnScriptErrorDebug is called when a run-time error occurs. The IActiveScriptSiteDebug interface gives the Script Host a chance to participate in debugging before the debugger is involved. In order for the Script Host to be notified when a run-time error occurs, a minimal implementation of IActiveScriptSiteDebug is required.
When the IActiveScript::SetScriptSite method is called, the script engine will QueryInterface the Host's IActiveScriptSite pointer for the IActiveScriptSiteDebug interface. If this fails, the script engine will attempt to contact the script debugger on its own. However, if the QueryInterface is successful, the script engine will then call IActiveScriptSiteDebug::GetApplication() to establish the debugging facilities for the scripting session. If IActiveScriptSiteDebug::GetApplication() fails, the script engine will conclude that debugging is not available on the machine, and revert to IActiveScriptSite::OnScriptError() for all error handling.
This is the IActiveScriptSiteDebug interface, with a minimal implementation:
Note In Visual C++ 2005, you must add the common language runtime support compiler option (/clr:oldSyntax) to successfully compile the previous code sample. To add the common language runtime support compiler option, follow these steps:
http://msdn2.microsoft.com/en-us/library/k8d11d4s.aspxAlternately, a Script Host may choose to have a more complete implementation of the IActiveScriptSiteDebug interface. For documentation about the IActiveScriptSiteDebug interface, visit the following MSDN Web site:
For more information about building ActiveX Script, click the following article number to view the article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/223139/ )How to add support for hosting VBScript to an ATL application
(http://support.microsoft.com/kb/183698/ )Axsh.exe demonstrates how to implement an active scripting host
(http://support.microsoft.com/kb/168214/ )MFCAxs.exe implements an Active Script host using MFC
(http://support.microsoft.com/kb/223389/ )Scripting.exe file contains the headers and libraries that are necessary to create ActiveX Script hosts and engines
Article ID: 232394 - Last Review: February 21, 2014 - Revision: 5.3