扔;抛出前最佳

时间:2010-08-15 04:47:41

标签: c#

  

可能重复:
  .NET - Throwing Exceptions best practices

您好,

我看到人们重新抛出异常,如下所示。哪一个是最佳的?为什么一种机制最优于另一种机制。

try
{
   // do something
}
catch (exception ex)
{
   // do something
   throw ex;
}

try
{
    // do something
}
catch (exception ex)
{
   // do something
   throw;
}

1 个答案:

答案 0 :(得分:0)

好吧,我不了解其他人,但有时我们会使用第二种方法来记录错误,然后将其捕获到其他地方。