#眉標=Enterprise Library #副標=設計模型套件系列(5) #大標=完善的例外處理機制提供者 #作者=文/王寧疆 ==程式1 =========== try { // 執行時可能會發生例外的程式碼. } catch(Exception ex) { ExceptionPolicy.HandleException(ex, "My Exception Policy"); //指定要使用名稱為My Exception Policy的例外處理機制處理發生的例外 } ================ ==程式2 =========== try { StreamReader sr = new StreamReader(Server.MapPath("~/NotExist.txt")); } catch (Exception ex) { bool rethrow = ExceptionPolicy.HandleException(ex, "Method Exception Policy"); if (rethrow) throw; } ================ ==程式3 =========== public void Page_Error(object sender, EventArgs e) { ExceptionPolicy.HandleException(Server.GetLastError(), "Web Page Exception Policy"); } ================ ==程式4 =========== void Application_Error(object sender, EventArgs e) { ExceptionPolicy.HandleException(Server.GetLastError(), "Web Site Exception Policy"); } ================ ==程式5 =========== public class UIException : ApplicationException { public UIException() { } public UIException(string strReason) : base(strReason) { } } ================