.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()
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");

Tuesday, April 05, 2005


Compile of VB Imports vs. C# using 

let's look at this Console App written in VB .

Imports System.Data
Imports System.Windows.Forms

Class class1
     Shared Sub Main()
End Sub

open the ConsoleApplication1.exe with ILDASM and have a look in manifest . UNFORTUNATELY vb compiler generated IL still references the system.data although it is not used in our app .

FORTUNATELY  This is not the case in C#. try the same thing in C# , we find that C# compiler is smart enough to remove the unreferenced dlls from IL .

a point to C# against VB :-)

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