用户代码未处理 WebProtocolException
我的 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,指出“A 中的 WebProtocolException CustomerID 与 B 中的 customerId 不匹配,用户代码未处理”。
但是,当我查看 fiddler 时,会显示状态代码 400,并且在 fiddler 的原始选项卡上会显示正确的 badrequest 响应和消息。
我很困惑为什么第二个 WebProtocol 没有被用户代码处理。
非常感谢任何建议!
扎尔
The code in my try block looks something like below:
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. 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".
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.
I'm confused to why the second WebProtocol is unhandled by user code.
Any suggestions is much appreciated!
Zal
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这个问题和答案 和这个 ASP.NET 论坛讨论。 您似乎遇到了同样的问题。
Take a look at this question and answer and this ASP.NET forum discussion. It seems you are running into the same issue.