COM:如何处理特定的异常?

标签 com exception-handling ado

我正在与 COM 对象(Microsoft ADO Recordset 对象)交谈。在某些情况下,记录集将返回失败(即否定)HRESULT , 带有消息:

Item cannot be found in the collection corresponding to the requested name or ordinal



我知道此错误消息的含义,知道它为什么会发生,以及我如何解决它。但我知道这些事情是因为我读了这条消息,幸运的是它是用我理解的语言写的。

现在我想特别处理这个异常。 COM 对象抛出了一个 HRESULT
0x800A0CC1

在理想情况下,Microsoft 会记录 what errors can be returned当我尝试访问时:
records.Fields.Items( index )

索引无效。但他们没有;他们最常说的是可能会发生错误,即:

If Item cannot find an object in the collection corresponding to the Index argument, an error occurs.



鉴于返回的错误代码没有记录,是 正确 当我试图捕获异常时,处理特定的返回代码“0x800A0CC1”:

Item cannot be found in the collection corresponding to the requested name or ordinal



?

由于 Microsoft 没有记录错误代码,因此他们将来会在技术上对其进行更改。

最佳答案

他们确实记录了这个错误代码,但很难找到:
ErrorValueEnum :

adErrItemNotFound    3265 -2146825023 0x800A0CC1    Item cannot be found in the collection that corresponds to the requested name or ordinal.

..so,作为它的'记录错误代码,明确测试它是安全的。

关于COM:如何处理特定的异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2951980/

相关文章:

c++ - 在 Recordset ADO 中找不到记录

performance - Delphi ADO 数据集过滤器

com - iTunes 似乎没有为其新的 Movement 和 Work 字段公开 COM 接口(interface)

com - Erlang 与 COM 对象的交互

PHP:我们如何在生产网站上禁用异常消息并将它们保留在开发中?

java - 理解 JAVA 中的 throw 关键字

c++ - 在 iOS 中启用异常

sql-server - ADO adTinyInt 与 SQL Server 中的 adUnsignedTinyInt

c# - 带有 32 位 VB6 COM 对象的 64 位 C#

multithreading - 这会使对象线程安全吗?