爲什麼基類的try-catch不捕獲派生類拋出的異常? 我錯過了什麼嗎?無法捕獲派生類拋出的異常
基類:
public class UmBase
{
protected Thread ThisThread;
protected UmBase(int cycleMs, UpdateManager updateManager,
string loggerFilename, string loggerFolder = "UpdateManager")
{
}
public void Start()
{
ThisThread = new Thread(Work);
ThisThread.Start();
}
public virtual void Iteration()
{
throw new Exception("Iteration Method should be overidden!");
}
public void Work()
{
while (IsProcessing)
{
try
{
Iteration();
}
catch (Exception exception)
{
Log.Error(exception.Message); //WANT TO HANDLE IT HERE
}
finally
{
Sleep(100);
}
};
}
}
派生類:
public class ReadParams : UmBase
{
public ReadParams(UpdateManager updateManager, int cycleMs = 60000)
: base(cycleMs, updateManager, "sss")
{
Iteration();
}
public override void Iteration()
{
try
{
DbParams.Set(); //EXCEPTION IS THROWN INSIDE
}
catch (Exception exception)
{
throw new Exception("Oops!", exception);
}
}
}
我在這裏Can we catch exception from child class method in base class in C#?閱讀並不能找到我的錯誤。
可能的重複[如何從C#派生類中的構造函數捕獲異常?](http://stackoverflow.com/questions/17266105/how-to-catch-exception-from-a-constructor-in -a衍生的類與 - c)中 – Brian 2014-12-04 22:50:12