扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:谢启东编译 来源:天极开发 2007年11月3日
关键字:
private void btnHandleException_Click (object sender, EventArgs e) { try { throw new Exception("This is a test exception"); } catch (Exception ex) { bool rethrow = ExceptionPolicy.HandleException (ex, "Global Policy"); if (rethrow) { throw; } } } |
using System; using System.Collections.Specialized; using System.Windows.Forms; using Microsoft.Practices.EnterpriseLibrary.Common.Configuration; using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder; using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling; using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration; namespace ExceptionMgmtBlockExample { [ConfigurationElementType (typeof(CustomHandlerData))] public class AppMessageExceptionHandler : IExceptionHandler { public AppMessageExceptionHandler(NameValueCollection ignore) {} public Exception HandleException (Exception exception, Guid correlationID) { DialogResult result = this.ShowThreadExceptionDialog (exception); if (result == DialogResult.Abort) Application.Exit(); return exception; } private DialogResult ShowThreadExceptionDialog(Exception e) { string errorMsg = e.Message + Environment.NewLine + Environment.NewLine; return MessageBox.Show(errorMsg, "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } } |
图2 |
private void btnLogException_Click(object sender, EventArgs e) { try { throw new Exception ("This is a test exception"); } catch (Exception ex) { bool rethrow = ExceptionPolicy.HandleException (ex, "Log Only Policy"); if (rethrow) { throw; } } } |
<add name="Log Only Policy"> <exceptionTypes> <add name="Exception" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="None"> <exceptionHandlers> <add logCategory="Default Category" eventId="100" severity="Error" title="Exception Management Application Exception" priority="0" formatterType="Microsoft. Practices.EnterpriseLibrary. ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary. ExceptionHandling" name="Logging Handler" type="Microsoft.Practices.EnterpriseLibrary. ExceptionHandling.Logging. LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary. ExceptionHandling.Logging"/> </exceptionHandlers> </add> </exceptionTypes> </add> |
图3 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者