捕獲和重新拋出.NET異常的最佳實踐在捕獲異常并重新拋出異常時,需要考慮哪些最佳實踐?我想確保Exception對象的InnerException堆棧痕跡被保存下來。下面的代碼塊在處理這些代碼塊的方式上有區(qū)別嗎?try{
//some code}catch (Exception ex){
throw ex;}與:try{
//some code}catch{
throw;}
3 回答

搖曳的薔薇
TA貢獻1793條經(jīng)驗 獲得超6個贊
throw;
try { // something that bombs here} catch (Exception ex){ throw;}
throw ex;
throw ex;

Smart貓小萌
TA貢獻1911條經(jīng)驗 獲得超7個贊
try{} catch(Exception ex){ throw new MoreDescriptiveException("here is what was happening", ex);}
- 3 回答
- 0 關(guān)注
- 584 瀏覽
添加回答
舉報
0/150
提交
取消