我有两个函数,它们的逻辑不同但异常处理基本相同:
public void DoIt1 // DoIt2 has different logic but same exception handling
{
try
... DoIt1 logic
catch (MySpecialException myEx)
{
Debug.WriteLine(myEx.MyErrorString);
throw;
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
throw;
}
}
由于DoIt1和DoIt2是从外部调用的,因此无法使用单个入口点。对于异常块的复制/粘贴是否是最佳方法?