小编Sco*_*ott的帖子

C#重新抛出异常

在多个方法之间抛出异常时,是否所有方法都重新抛出异常?例如

Method1()
{
   Method2();
}

Method2()
{
   try
   {
      // Do something
   }
   catch
   {
      throw;
   }
}
Run Code Online (Sandbox Code Playgroud)
try
{
   Method1();
}
catch
{
   // Do something about exception that was thrown from Method2()
}
Run Code Online (Sandbox Code Playgroud)

请注意,在Method1(),我也没必要换Method2()一个try块,我应该是什么?

.net c# exception

6
推荐指数
2
解决办法
1423
查看次数

标签 统计

.net ×1

c# ×1

exception ×1