捕获使用C ++编写的ActiveX控件引发的JavaScript异常 [英] catching exceptions in Javascript thrown from ActiveX control written in C++

查看:224
本文介绍了捕获使用C ++编写的ActiveX控件引发的JavaScript异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C ++中编写了一个ActiveX控件,它会在控件中出现错误条件时抛出(C ++)异常。调用表示控件实例的对象的Javascript代码由try-catch块包围:

I've written an ActiveX control in C++ that throws (C++) exceptions out when error conditions occur within the control. The Javascript code that invokes the object representing an instance of the control is surrounded by a try - catch block:

try
{
    var controlInstance = window.controlInstance;

    ... perform operations on controlInstance ...
}
catch (e)
{
    alert("something bad happened");
}

现在,当我在IE8(或7或6)下运行此代码一个连接到它的Visual Studio(2008)调试器,一切都按预期运行 - 控件是否使用或不使用DEBUG进行编译。但是,当运行没有调试器的浏览器时,当异常跨越控件和JScript之间的边界时,IE会崩溃(真的)。

Now, when I run this code under IE8 (or 7 or 6) with a Visual Studio (2008) debugger attached to it, everything works as expected - whether the control is compiled with or without DEBUG on. However, when running the browser without a debugger attached, IE crashes (really) when an exception crosses the boundary between the control and JScript.

有没有人有任何建议解决这个问题?我意识到,我可以改变控件的界面来传递异常,作为一个参数,但我真的不会这样做。

Does anyone have any suggestions around how to solve this problem? I realize that I can change the control's interface to pass the exception back as an argument but I really would rather not make such a change.

任何帮助将不胜感激。 / p>

Any help would be appreciated.

推荐答案

你如何从C ++传递异常?如果要将异常传播给JavaScript,则一般 throw 不起作用。您需要抛出类型 COleDispatchException 的异常,正确的方法是调用

How are you passing the exception from C++? A general throw does not work if you want to propagate your exception to javascript. You need to throw exception of type COleDispatchException and the right way to do is calling

AfxThrowOleDispatchException(101, _T("Exception Text Here")); // First parameter is exception code. 

参考: http://doc.sumy.ua/prog/active_x/ch03.htm#Heading20

这篇关于捕获使用C ++编写的ActiveX控件引发的JavaScript异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆