Question

I'm trying to catch and handle a specific HttpException, namely "The remote host closed the connection. The error code is 0x800704CD."

My intention is to add a Catch for the HttpException to the relevant Try block and test for the error code that is generated. Sample code:

Try
    // Do some stuff
Catch exHttp As HttpException
    If exHttp.ErrorCode.ToString() = "0x800704CD" Then DoSomething()
Catch ex As Exception
    // Generic error handling
End Try

But I can't work out how to extract the error code displayed in the exception (i.e. "0x800704CD") from the HttpException object. Converting the integer value of the ErrorCode property to hex returns "800704CD" so clearly I'm not understanding how this code is generated.

Thanks.

Was it helpful?

Solution

Try the Below Code:

 Try
    // Do some stuff
        Catch exHttp As HttpException
            If exHttp.ErrorCode = &H800704CD Then DoSomething()
        Catch ex As Exception
    // Generic error handling
        End Try

OTHER TIPS

ErrorCode property is an integer so just test for integer value, no reason to convert to hexadecimal or string.

0x in most programming languages means the following characters denote a hexadecimal number, i.e. 0x800704CD means 800704CD will be interpreted as a hexadecimal number. For VB use &H.

More on VB.Net literals:

http://msdn.microsoft.com/en-us/library/s9cz43ek.aspx

http://msdn.microsoft.com/en-us/library/dzy06xhf.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top