ASP.NET How to get HttpException ErrorCode

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.

asp.net
httpexception
asked on Stack Overflow Nov 19, 2012 by AGB

2 Answers

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
answered on Stack Overflow Nov 19, 2012 by RG ATHISH
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

answered on Stack Overflow Mar 22, 2014 by user3285954

User contributions licensed under CC BY-SA 3.0