相关疑难解决方法(0)

捕获和重新抛出.NET异常的最佳实践

捕获异常并重新抛出异常时需要考虑哪些最佳实践?我想确保保留Exception对象InnerException和堆栈跟踪.以下代码块在处理此方式时是否存在差异?

try
{
    //some code
}
catch (Exception ex)
{
    throw ex;
}
Run Code Online (Sandbox Code Playgroud)

VS:

try
{
    //some code
}
catch
{
    throw;
}
Run Code Online (Sandbox Code Playgroud)

.net c# exception-handling rethrow

279
推荐指数
8
解决办法
18万
查看次数

标签 统计

.net ×1

c# ×1

exception-handling ×1

rethrow ×1