Closing Application on Error
In the constructor of my initial windows form class I would like to do some set up of various parameters. If errors occur during this setup I would like an error message to appear and the entire application to end. Unfortunately, the initial form appears and must be closed. I have tried adding a close() in the constructor but probably because the form has not been shown at this point this doesn't work. Some code snippets are as follows. Any ideas? TIA
static void Main()
{
Application.Run(new Master());
}
public class Master : System.Windows.Forms.Form
{
InitializeComponent();
// test new data Access class
try
{
da = new DataAccess();
}
catch (Exception err)
{
MessageBox.Show(err.ToString());
Close(); // note: doesn't work
return; // returns but form is still displayed
}
.....
}