It appears that this HttpException (0x80072746 - The remote host closed the connection) can be thrown if, for example, the user closes the window whilst we are transmitting a file. Even if we send the files in smaller blocks and check the client is still connected, the exception can still occur. We want to be able to catch this specific exception, to ignore it.
The ErrorCode provided in the HttpException is an Int32 - too small to hold 0x80072746, so where do we find this number?
Int32 is not really too small to hold 0x80072746; only in “normal” notation, this number is negative: 0x80072746 == -2147014842, you can create a constant to compare the error code against:
const int ErrConnReset = unchecked((int)0x80072746);
or
const int ErrConnReset = -2147014842;
The HttpException.ErrorCode property gives you the error code you are looking for. Make it look similar to this:
try {
//...
}
catch (HttpException ex) {
if ((uint)ex.ErrorCode != 0x80072746) throw;
}
In computer science, a negative integer is represented in hexadecimal with a the first bit set to 1 (source: wikipediat).
According that, the hexadecimal number 0x80072746
can be written in base 2 :
1000 0000 0000 0111 0010 0111 0100 0110
The first bit is set... then it correspond actually to this number :
-0111 1111 1111 1000 1101 1000 1011 1010
which can finally be represented in base 10 like this :
-2147014842
which is finally, actually an correct integer.
Don't know if it can help you to solve the problem.
来源:https://stackoverflow.com/questions/5104843/how-to-catch-a-specific-httpexception-0x80072746-in-an-ihttphandler