Add a simple error catcher for most file loads.

This commit is contained in:
Tim Young 2017-07-31 16:23:38 -05:00
parent b7b5525413
commit 857c8750ba

View File

@ -1671,31 +1671,39 @@ namespace EduNetworkBuilder
} }
//If it is a network file //If it is a network file
string extension = Path.GetExtension(filename).ToLower(); string extension = Path.GetExtension(filename).ToLower();
//MessageBox.Show(filename + " " +extension); //MessageBox.Show(filename + " " +extension);
if (extension == ".enbx") try
{ {
PrepForLoad(); if (extension == ".enbx")
myNetwork.Load(filename); {
UpdateMenu(); PrepForLoad();
UpdateForm(); myNetwork.Load(filename);
} else if(extension == ".enbu") UpdateMenu();
{ UpdateForm();
CurrentUser = new PersonClass(filename); }
OurSettings = NB.GetSettings(); //Grab the new settings from the user else if (extension == ".enbu")
UpdateMenu(); {
CurrentUser = new PersonClass(filename);
OurSettings = NB.GetSettings(); //Grab the new settings from the user
UpdateMenu();
//Now, open a new window to edit them. //Now, open a new window to edit them.
PersonProfileForm PPF = new PersonProfileForm(CurrentUser); PersonProfileForm PPF = new PersonProfileForm(CurrentUser);
CurrentUser = PPF.Edit(); //This does the form as dialog. When we come back, update the menu. CurrentUser = PPF.Edit(); //This does the form as dialog. When we come back, update the menu.
UpdateMenu(); UpdateMenu();
}
else
{
MessageBox.Show(NB.Translate("NB_InvalidFile"));
Close();
return; //We return here so we do not register the filename...
}
if (OurSettings != null) OurSettings.RegisterFileAsLoaded(filename);
} }
else catch (Exception e)
{ {
MessageBox.Show(NB.Translate("NB_InvalidFile")); MessageBox.Show("Error: " + e.ToString());
Close();
return; //We return here so we do not register the filename...
} }
if (OurSettings != null) OurSettings.RegisterFileAsLoaded(filename);
} }
private void loadRecentFilename(object sender, EventArgs e) private void loadRecentFilename(object sender, EventArgs e)