"Chris Fink" <ch*********@hotmail.com> a écrit dans le message de
news:uW**************@TK2MSFTNGP12.phx.gbl...
I have written a c# windows application which is occasionally throwing
this messagebox popup exception in the test environment:
"application has generated an exception that could not be handled"
I have try - catch around the entire application and would expect this to
prevent any type of messagebox from appearing. Any ideas on why this is
occuring and how to remedy? Are there settings in the project
configuration properties that will disable this? I can't seem to recreate the error in
our development environment and I dont have studio installed on test so there
is no way for me to find out more info regarding this error (that I am aware
of). All suggestions are appreciated.
thanks in advance!
Maybe you should have a look at the event :
AppDomain.UnhandledException
It enables you to catch any exception not caught in the main method or
anywhere else.
Here is a sample from the MSDN documentation :
public static void Main() {
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new
UnhandledExceptionEventHandler(MyHandler);
try {
throw new Exception("1");
} catch (Exception e) {
Console.WriteLine("Catch clause caught : " + e.Message);
}
throw new Exception("2");
// Output:
// Catch clause caught : 1
// MyHandler caught : 2
}
static void MyHandler(object sender, UnhandledExceptionEventArgs args) {
Exception e = (Exception) args.ExceptionObject;
Console.WriteLine("MyHandler caught : " + e.Message);
}