try
{
// call to Com Method
}
catch (COMException e)
{
if (e.ErrorCode == 0x80040154) // REGDB_E_CLASSNOTREG.
{
// handle this error.
}
}
I would like to check if com exception is thrown due to REGDB_E_CLASSNOTREG
then handle it. I tried with the code above but it gives warning:
Comparison to integral constant is useless; the constant is outside the range of type 'int'
I believe this error is due to 0x80040154
is not in Int32 range.
Can you suggest any possible solution? or Is there any other way to check this?
Use the unchecked keyword:
catch (COMException ex) {
if (ex.ErrorCode == unchecked((int)0x80040514)) {
//...
}
}
Comparing with its integer equivalent works fine:
if (e.ErrorCode == -2147287036) // REGDB_E_CLASSNOTREG.
{
// handle this error.
}
You can also try by using some text that is displayed in Exception message/Error Message like follows
try
{
// call to Com Method
}
catch (COMException e)
{
if (e.ToString().Contains("Your Error Text here")) // REGDB_E_CLASSNOTREG.
{
// handle this error.
}
}
来源:https://stackoverflow.com/questions/7790203/how-to-check-errorcode-for-regdb-e-classnotreg