我有一个类,其中处理与sql相关的所有事情,称为sql helper。 现在我想要实现的是,捕获来自这个特定类的occer的所有异常并记录它们。因为这个类是从几个地方调用的,并且已经有超过25-30个方法。我发现编写异常处理的每一种方法都很繁琐。
这是Windows应用程序有没有更好的方法来处理这个问题。 例如我们在asp.net中的方式
Application_Error()
{
}
答案 0 :(得分:0)
使用:
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyExceptionHandler);
http://msdn.microsoft.com/es-es/library/system.appdomain.unhandledexception.aspx
答案 1 :(得分:0)
Application.ThreadException
将允许您在不终止应用程序的情况下捕获未处理的异常。
AppDomain.UnhandledException
将终止应用。