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.
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