1 在这一般处理程序的方法中,当执行完逻辑后,
打印
context.Response.Write(returnValue);
context.Response.End();
结束时,成功了还是会走异常。
会报进程终止异常,处理方法,在catch (Exception)前面增加
//执行 context.Response.End();时会报进程终止的异常,下面是当这种情况下进入
catch (System.Threading.ThreadAbortException)
{
}
这样就不会进异常中了。
例:
try
{
returnValue = "{\"code\":10000,\"msg\": \"成功!\"}";
context.Response.Write(returnValue);
context.Response.End();
}
//执行 context.Response.End();时会报进程终止的异常,下面是当这种情况下进入
catch (System.Threading.ThreadAbortException)
{
}
catch (Exception)
{
returnValue = "{\"code\":10002,\"msg\": \"程序异常!\"}";
context.Response.Write(returnValue);
context.Response.End();
}
博客内容讲述了在ASP.NET中,使用`context.Response.End()`可能会引发进程终止异常。为了解决这个问题,作者建议在`try-catch`块中特别捕获`System.Threading.ThreadAbortException`,并提供了一个示例代码片段来展示如何优雅地处理这种情况,避免程序进入异常状态。
8717

被折叠的 条评论
为什么被折叠?



