.comment-link {margin-left:.6em;}

Thursday, April 14, 2005

 

Centralized Exception handling in Windows Forms :


can we really have a centralized exception management in windows forms apps ?
we always hear this :
1- i need a procedure to be triggered whenever any error in the applciation is fired (may be just to log and trace) without writing try and catch blocks.


in VB.NET :


shared sub main()
      AddHandler
Application.ThreadException, AddressOf s1
end sub


Sub s1(ByVal sender As Object, ByVal e As Threading.ThreadExceptionEventArgs)
     MessageBox.Show("Centralized Exception trapping")
End Sub


in C#.NET :


static void main()
{
   Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
}


private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
     MessageBox.Show("Centralized Exception trapping");
}


Comments:
You need a bit more to accomplish GEH:
http://www.danielmoth.com/Blog/2004/08/global-exception-handling-net-v11-part.html
 
Post a Comment

Links to this post:

Create a Link



<< Home

This page is powered by Blogger. Isn't yours?