Below an example from "Windows Forms Programming with C#", by Erik Brown
(Manning) p. 228. According to me the example is wrong. The message box does
not get activated when an erroneous file name is entered. Could someone
indicate the error and suggest alternative code to make this example work?
Patrick
private void menuSave_Click( object sender, System.EventArg s e)
{
if (_album.FileNam e == null)
{
// Need to select an album file
menuSaveAs_Clic k(sender, e);
}
else
{
try
{
// Save the album in the current file
_album.Save();
_bAlbumChanged = false;
}
catch (Exception ex)
{
string msg = "Unable to save file {0}"
+ " - {1}\nWould you like to save"
+ " the album in an alternate file?";
DialogResult result = MessageBox.Show (this,
String.Format(m sg, _album.FileName , ex.Message),
"Save Album Error",
MessageBoxButto ns.YesNo,
MessageBoxIcon. Error,
MessageBoxDefau ltButton.Button 2);
if (result == DialogResult.Ye s)
{
menuSaveAs_Clic k(sender, e);
}
}
}
}
(Manning) p. 228. According to me the example is wrong. The message box does
not get activated when an erroneous file name is entered. Could someone
indicate the error and suggest alternative code to make this example work?
Patrick
private void menuSave_Click( object sender, System.EventArg s e)
{
if (_album.FileNam e == null)
{
// Need to select an album file
menuSaveAs_Clic k(sender, e);
}
else
{
try
{
// Save the album in the current file
_album.Save();
_bAlbumChanged = false;
}
catch (Exception ex)
{
string msg = "Unable to save file {0}"
+ " - {1}\nWould you like to save"
+ " the album in an alternate file?";
DialogResult result = MessageBox.Show (this,
String.Format(m sg, _album.FileName , ex.Message),
"Save Album Error",
MessageBoxButto ns.YesNo,
MessageBoxIcon. Error,
MessageBoxDefau ltButton.Button 2);
if (result == DialogResult.Ye s)
{
menuSaveAs_Clic k(sender, e);
}
}
}
}