handle bad requests better (don't fail when connection not available)

Don't crash when writing log to protected directory.
This commit is contained in:
Lars Brubaker 2015-05-28 11:03:45 -07:00
parent ab0f591773
commit 7d8dff4040
5 changed files with 32 additions and 5 deletions

View file

@ -214,6 +214,9 @@ namespace MatterHackers.MatterControl
base.OnDraw(graphics2D);
}
readonly static string writeFaildeWaring = "WARNING: Write Failed!".Localize();
readonly static string cantAccessPath = "Can't access '{0}'.".Localize();
private void onExportLogFileSelected(SaveFileDialogParams saveParams)
{
if (saveParams.FileName != null)
@ -221,7 +224,17 @@ namespace MatterHackers.MatterControl
string filePathToSave = saveParams.FileName;
if (filePathToSave != null && filePathToSave != "")
{
textScrollWidget.WriteToFile(filePathToSave);
try
{
textScrollWidget.WriteToFile(filePathToSave);
}
catch(UnauthorizedAccessException e)
{
PrinterOutputCache.Instance.PrinterLines.Add("");
PrinterOutputCache.Instance.PrinterLines.Add(writeFaildeWaring);
PrinterOutputCache.Instance.PrinterLines.Add(cantAccessPath.FormatWith(filePathToSave));
PrinterOutputCache.Instance.PrinterLines.Add("");
}
}
}
}