public static void ReadTitlesFromFile(string filePath) { try { if (!File.Exists(filePath)) { return; } using (var sr = new StreamReader(filePath)) { string line; while ((line = sr.ReadLine()) != null) { TitleNamesCollection.AddItem(line); } } } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file path value is an empty string."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (FileNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate this file. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (IOException ex) { MyMessagesClass.ErrorMessage = "File path has invalid characters in it."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } }
public static void ReadTitlesFromFile(string filePath) { try { if (!File.Exists(filePath)) { return; } using (var sr = new StreamReader(filePath)) { string line; while ((line = sr.ReadLine()) != null) { TitleNamesCollection.AddItem(line); } } } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = V6 + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = V7; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (FileNotFoundException ex) { MyMessagesClass.ErrorMessage = V8 + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = V9; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (IOException ex) { MyMessagesClass.ErrorMessage = V10; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } }