我總是使用try catch來處理與數據庫相關的操作,例如。數據庫插入,更新和刪除應該包含在try/catch中嗎?
try
{
DataContext.AddtoObjectname(obj);
DataContext.SaveChanges();
}
catch(Exception e)
{
throw new Exception("Problems adding object" + e);
}
但我讀到的try/catch影響表現在這裏 -
Do try/catch blocks hurt performance when exceptions are not thrown?
所以我要補充嘗試捕捉的東西,我做以上或者我應該選擇otherwise.Thanks對您有所幫助。
是的,否則你將如何告訴客戶端該操作的狀態。 – 2010-06-23 16:27:17
如何捕捉所有異常,然後拋出一個新的幫助? – 2010-06-23 16:28:46