COM 中的异常
我正在使用 COM 代码编写一个接口,并且我知道该接口的唯一用户是我自己的代码(间接)。如果我抛出异常,我可以在中间库的另一侧捕获它吗?这是一个终止条件,因此世界上最优雅的清理并不是有史以来最大的交易。
I'm writing an interface with COM code and I know that the only user of this interface is my own code (indirectly). If I throw an exception, can I catch it on the other side of the library that's in the middle? This is a termination condition so the world's most graceful cleanup isn't the biggest deal ever.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不允许异常跨越 COM 接口边界。由于 C++ 异常没有二进制协定,因此 COM 无法将它们从一个线程封送到另一个线程。现在这可能不是一个大问题,但如果您决定更改 COM 对象的线程模型,那么以后可能会出现问题。
另外,如果您决定用 C#(或 Delphi 或其他)重写应用程序的前端,会发生什么情况?各种 COM 互操作框架可以理解 COM HRESULTS,但 C++ 异常则不能(C++ 异常没有二进制协定)。
Exceptions aren't allowed to flow across a COM interface boundary. Because there is no binary contract for C++ exceptions, COM cannot marshal them from one thread to another. This might not be a huge issue now but it may be a problem later on if you decide to change the threading model of your COM object.
Also, what happens if you decide that you want to rewrite the front end of your application in C# (or Delphi or whatever)? COM HRESULTS are understood by the various COM interop frameworks but C++ exceptions aren't (no binary contract for C++ exceptions).