Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9850


Ignore:
Timestamp:
08/05/13 16:42:08 (9 years ago)
Author:
mkommend
Message:

#2081: Added exception handling to the TextFileView.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Data.Views/3.3/Path Views/TextFileView.cs

    r9841 r9850  
    2525using System.Windows.Forms;
    2626using HeuristicLab.MainForm;
     27using HeuristicLab.PluginInfrastructure;
    2728
    2829namespace HeuristicLab.Data.Views {
     
    216217      if (!File.Exists(path)) return null;
    217218      string fileContent = string.Empty;
    218       using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
    219         using (StreamReader streamReader = new StreamReader(fileStream)) {
    220           fileContent = streamReader.ReadToEnd();
    221         }
     219      try {
     220        using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
     221          using (StreamReader streamReader = new StreamReader(fileStream)) {
     222            fileContent = streamReader.ReadToEnd();
     223          }
     224        }
     225      }
     226      catch (Exception e) {
     227        ErrorHandling.ShowErrorDialog(e);
    222228      }
    223229      return fileContent;
     
    225231
    226232    private static void WriteFile(string path, string fileContent) {
    227       using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None)) {
    228         using (StreamWriter streamWriter = new StreamWriter(fileStream)) {
    229           streamWriter.Write(fileContent);
    230         }
     233      try {
     234        using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None)) {
     235          using (StreamWriter streamWriter = new StreamWriter(fileStream)) {
     236            streamWriter.Write(fileContent);
     237          }
     238        }
     239      }
     240      catch (Exception e) {
     241        ErrorHandling.ShowErrorDialog(e);
    231242      }
    232243    }
Note: See TracChangeset for help on using the changeset viewer.