Saturday, February 20, 2010

Disbale JIT in .net / Application level Exception handling in .net

1 comment
downloadDownload Code Example

I was developing windows application for a well known company of World. This application was in 2005.

As per requirement I have to show user defined message whenever an Exception occurs in the application.

The answer is very simply write a simple Try{},Catch{} statement to handle exception.
Suppose I have a code of 1000 line unwanted code and error handling creates extra thread while executing the application. I had search on the internet and found a solution to disable the JIT debugger. It works but still it is showing the application information related to functions etc. used in the code.

Now, a major issue had risen from client, i.e. he don’t want to show JIT information to user he wants to show his own message whenever any Exception occurs.

Offf…. Now that’s the task to which needs to done. I cannot use Try{},Catch{} as this decrease the application performance. Finally I came to the solution. I had wired an event with application to handle application error. Here is the code.

static void Main()
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
Application.Run(new Form1());

static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
MessageBox.Show("Illegal operation or command.", "Illegal operation", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Now, run your code and click on the button, it will show are exception while you are running the application within the .net environment.

Now browser the directory and Run you EXE file and again click in the button, now it will not show exception rather show the message which you wants to display.

This is a good approach it will show exception and source in while debugging and show and user defined message in EXE


IT Solutions said...

You completed certain fine points there. I did a search on the matter and found most people will agree with your blog.

Great Solution!