How to catch a specific HttpException (#0x80072746) in an IHttpHandler

旧街凉风 提交于 2019-12-07 13:03:05

问题


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?


回答1:


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;



回答2:


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;
        }



回答3:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!