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:
Click Project, and then click ProjectName Properties.
Note ProjectName is a placeholder for the name of the project.
Expand Configuration Properties, and then click General.
In the right pane, click to select Common Language Runtime Support, Old Syntax (/clr:oldSyntax) in the Common Language Runtime support project settings.
Click Apply, and then click OK.
For more information about common language runtime support compiler options, visit the following Microsoft Developer Network (MSDN) Web site:
Alternately, 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: