using System; namespace Demo { class Program { static void Main(string[] args) { try { BLLLayer(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); Console.WriteLine("==================================="); Console.WriteLine(ex.ToString()); } Console.ReadKey(); } static void BLLLayer() { try { DAOLayer(); } catch (Exception ex) { //throw; //可溯源到DAO //throw ex; //可溯源終點就是這裏 //throw new Exception("BLL層異常"); //可溯源終點就是這裏,拋出新的異常,吞併原來的異常 //throw new Exception("BLL層異常", ex); //可溯源終點就是這裏,拋出新的異常,帶着原來的異常 } } static void DAOLayer() { try { throw new Exception("DAO層異常"); } catch { throw; } } } }