【问题标题】:WebProtocolException was unhandled by user code用户代码未处理 WebProtocolException
【发布时间】:2011-07-27 09:43:21
【问题描述】:

我的 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);
}

发生的情况是条件满足并且条件中的WebProtolException被满足并抛出。然而,在调试外部 WebProtocolException 时也会抛出“WebProtocolException CustomerID in A does not match customerId in B was unhandled by user code”。

但是,当我查看 fiddler 时,会显示 400 的状态代码,并且在 fiddler 的原始选项卡上会显示正确的 badrequest 响应和消息。

我很困惑为什么第二个 WebProtocol 没有被用户代码处理。

非常感谢任何建议!

扎尔

【问题讨论】:

    标签: c# wcf unhandled-exception custom-exceptions


    【解决方案1】:

    看看这个question and answer 和这个ASP.NET forum discussion. 看起来你遇到了同样的问题。

    【讨论】:

      猜你喜欢
      • 2013-12-28
      • 2014-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多