2

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.

3
  • in the sample code you are assigning 0x800704CD whicgh should generate another exception Commented Nov 19, 2012 at 12:41
  • have you tried to print the stack trace and see what does it have Commented Nov 19, 2012 at 12:42
  • exHttp.ErrorCode.ToString() returns the integer value of the error code, converted to string e.g. "-2147023667" Commented Nov 19, 2012 at 12:54

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks RG ATHISH, adding the &H works. Could you explain why though?
0x800704CD for C#.net , &H800704CD for vb.net
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.