views:

197

answers:

2

I'm handling all of my unhanded exception in the code but whenever one happens (not during debugging) I get my error window and as soon as it closes "Unhandled application exception has occurred in your application" window pops up. How do I suppress it?

PS : I am not using ASP.NET , I'm using Windows Forms

A: 

I would use exception shielding.

Windows App Example

This one shows use for Services

Exception Shielding

Its part of the enteprise library, and allows you to filter out exceptions as well as remap them, to hide the details.

Nix
+3  A: 

You cannot suppress AppDomain.UnhandledException. Something really nasty happened, a thread in your program died from a heart attack. The odds that the program will continue to run in a meaningful way are zero, .NET puts an end to the misery by terminating the program.

Write an event handler for the AppDomain.CurrentDomain.UnhandledException event and log or display the value of e.ExceptionObject.ToString() so you know what caused the mishap. That gives you a hint how to fix your code. If any, it may well be something that you cannot fix yourself. Some kind of database server malfunction for example. Doing anything to intentionally hide the error is therefore a Very Bad Idea. Your customer's support staff will have no idea what to do.

Hans Passant