我正在与 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/