如何检查regdbe_classnotreg的ErrorCode
本文关键字:classnotreg ErrorCode regdbe 何检查 检查 | 更新日期: 2023-09-27 18:11:20
try
{
// call to Com Method
}
catch (COMException e)
{
if (e.ErrorCode == 0x80040154) // REGDB_E_CLASSNOTREG.
{
// handle this error.
}
}
我想检查是否com异常抛出由于REGDB_E_CLASSNOTREG
然后处理它。我尝试了上面的代码,但它给出了警告:
Comparison to integral constant is useless; the constant is outside the range of type 'int'
我认为这个错误是由于0x80040154
不在Int32范围内。
你能提出一些可能的解决方案吗?或者还有其他方法来检查吗?
使用未选中的关键字:
catch (COMException ex) {
if (ex.ErrorCode == unchecked((int)0x80040514)) {
//...
}
}
与其等效的整数比较效果良好:
if (e.ErrorCode == -2147287036) // REGDB_E_CLASSNOTREG.
{
// handle this error.
}
您也可以尝试使用异常消息/错误消息中显示的一些文本,如以下
try
{
// call to Com Method
}
catch (COMException e)
{
if (e.ToString().Contains("Your Error Text here")) // REGDB_E_CLASSNOTREG.
{
// handle this error.
}
}