문제

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?

도움이 되었습니까?

해결책 2

Comparing with its integer equivalent works fine:

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

다른 팁

Use the unchecked keyword:

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

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.
    }
 } 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top