【发布时间】:2021-12-19 05:55:49
【问题描述】:
我有以下代码。这已经存在。 catch 的每个块到底在做什么。这是在 ASP.NET Web API 上处理异常的正确方法吗?如果不是,我该如何正确处理异常。
注意:第二个 catch 块中的 CustomServiceException 只是扩展了 Exception 类。
try
{
... I am calling my exteral API here using HttpClient class
}
catch(HttpRequestException ex)
{
Logger.Error("my error message", ex.Message);
}
catch(CustomServiceException)
{
throw;
}
catch (Exception ex)
{
Logger.Error("my error message",ex);
}
【问题讨论】:
标签: c# asp.net-mvc exception asp.net-web-api