[英]Handling ActiveX Control Exceptions(C#) in Javascript
我已經使用COM Interop在C#中編寫了ActiveX控件,以公開方法/屬性。
[ComVisible(true)]
class COMClass:ICOMClass
{
public string methodA()
{
string str = "abc";
if(str != "abcd")
throw new Exception("invalid string");
return str;
}
}
[ComVisible(true)]
interface ICOMClass
{
string methodA();
}
有沒有一種方法可以處理JavaScript中C#引發的異常? 我四處張望,但找不到任何東西?
例如。
var x = new ActiveXObject("COMClass");
try{
x.methodA
}
catch(e) {
alert(e);
}
呼叫alert(e.message)
對我alert(e.message)
。
確保您的ActiveX類正在實現IObjectSafety
:
using System;
using System.Runtime.InteropServices;
[ComImport()]
[Guid("CB5BDC81-93C1-11CF-8F20-00805F2CD064")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IObjectSafety
{
[PreserveSig()]
int GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out int pdwEnabledOptions);
[PreserveSig()]
int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.