Here is a code sample for you, as it's really good to know:
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += delegate(object sender, System.Threading.ThreadExceptionEventArgs e) {
MessageBox.Show(
string.Format("{0}:\n{1}", e.Exception.GetType().Name, e.Message),
string.Format(" {0}: Exception", Application.ProductName),
MessageBoxButtons.OK,
MessageBoxIcon.Error);
};
I usually call first line from application entry point (
Main
), and the rest of it — form a constructor of a main form.
—SA