I usually create a class, called
EntryPoint.cs
[STAThread]
static void Main(string[] args)
{
try
{
Application.Run(new Form1()); //Whatever your startup form is
}
}
catch (Exception ex)
{
//Notify User
MessageBox.Show( "A (uncaught) exception has occured. MyApp
cannot continue." );
//Shut down application
Application.Exit( );
}
}
This will catch any uncaught exceptions.
You should should google
try catch finally brad abrams
and you can read where
"You should be writing many many more
try/finally
blocks
and not so many
try/catch/finally
blocks.
You should also check out
http://www.microsoft.com/downloads/d...B-8F22CA173E02
or
http://msdn.microsoft.com/library/de.../html/ehab.asp
Its default behavior is to write to the EventLog, but you can EXPAND this if
you need to.
I wrote my own custom publisher which allows any/all of 3 things:
Write a .log file on users local machine.
Send an email.
Update a db with insertion.
While the EMAB (Exception Management Application Block) is older, its still
good stuff.
The EMAB basically requires some basic app.config setup. and then you add
ONE line of code.
altered from above
catch (Exception ex)
{
ExceptionManager.Publish(ex); // Yes, this is it. Even for my
..logfile, emailer, db update, this is all I put in my code. I set up
everything in app.config.
//Notify User
MessageBox.Show( "A (uncaught) exception has occured. MyApp
cannot continue." );
//Shut down application
Application.Exit( );
}
"CharlieC" <go****@ccurtis.comwrote in message
news:11*********************@c28g2000cwb.googlegro ups.com...
I am writing a windows C# application, and I want to ensure that all
exceptions, handled or otherwise, are logged to the local event log.
I can do this for the handled exceptions, but I am not sure how to
override (?) the system exception such that un-handled exceptions are
logged.
I know that you can do this in delphi by pointing the application
exception to your own base exception handler. Is there any similar way
that this can be done in the dot.net V2 framework?
Many thanks in advance