简体   繁体   English

用户代码未处理WebProtocolException

[英]WebProtocolException was unhandled by user code

The code in my try block looks something like below: 我的try块中的代码如下所示:

catch (ThinkBusinessLogicException ex)
{
    var message = (ex.InnerException != null) ? ex.InnerException.ToString() : ex.Message;

    if (message == "CustomerID in A does not match customerId in B")
    {
        Error = new ErrorStore("400", "1", "CustomerID in A does not match customerId in B");
        throw new WebProtocolException(HttpStatusCode.BadRequest, Error.Description, Error.Generate(), null, null);
    }

    throw new WebProtocolException(HttpStatusCode.InternalServerError, message, new ErrorStore("500", "1", message).Generate(), null, null);
}

What happens is that the condition is met and the WebProtolException in the condition is met and thrown. 发生的情况是满足条件,并且满足并抛出了该条件中的WebProtolException。 However while debugging the outter WebProtocolException is also thrown stating that "WebProtocolException CustomerID in A does not match customerId in B was unhandled by user code". 但是,在调试外部WebProtocolException时,也会引发“用户代码未处理A中的WebProtocolException客户ID与B中的customerId不匹配”的情况。

However when I take a look in fiddler the status code of 400 is displayed and on the raw tab in fiddler dispalys the correct badrequest response with the message. 但是,当我查看提琴手时,会显示状态代码400,并且在提琴手的原始选项卡上会显示该消息的正确badrequest响应。

I'm confused to why the second WebProtocol is unhandled by user code. 我对为什么第二个WebProtocol无法由用户代码处理感到困惑。

Any suggestions is much appreciated! 任何建议,不胜感激!

Zal 扎尔

Take a look at this question and answer and this ASP.NET forum discussion. 看看这个问题和答案以及这个ASP.NET论坛讨论。 It seems you are running into the same issue. 看来您遇到了同样的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM