2011-10-17 15 views
2
try 
{ 
    // call to Com Method 
} 
catch (COMException e) 
{ 
    if (e.ErrorCode == 0x80040154) // REGDB_E_CLASSNOTREG. 
    { 
     // handle this error. 
    } 
} 

我想检查com例外是否由于REGDB_E_CLASSNOTREG而引发,然后处理它。我试着用上面的代码,但它给出了警告:如何检查REGDB_E_CLASSNOTREG的ErrorCode?

Comparison to integral constant is useless; the constant is outside the range of type 'int' 

我相信这个错误是由于0x80040154不在的Int32范围。

你能提出任何可能的解决方案吗?或者有没有其他的方法来检查这个?

回答

1

其整数等效比较正常工作:

if (e.ErrorCode == -2147287036) // REGDB_E_CLASSNOTREG. 
{ 
    // handle this error. 
} 
0

您还可以通过使用显示在异常消息/错误消息的一些文字,尝试像如下

try 
{ 
    // call to Com Method 
} 
catch (COMException e) 
{ 
    if (e.ToString().Contains("Your Error Text here")) // REGDB_E_CLASSNOTREG. 
    { 
    // handle this error. 
    } 
} 
3

使用选中关键字:

 catch (COMException ex) { 
      if (ex.ErrorCode == unchecked((int)0x80040514)) { 
       //... 
      } 
     }