[longomatch] Catch errors gracefully when a project fails to open



commit 3965577fd7346cd4ffded3c42caf064605b56a62
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Sep 23 03:03:03 2014 +0200

    Catch errors gracefully when a project fails to open

 LongoMatch.Core/Common/Exceptions.cs            |   17 +++++++++++++++++
 LongoMatch.Services/Services/FileDB.cs          |   15 +++++++++------
 LongoMatch.Services/Services/ProjectsManager.cs |    8 +++++++-
 3 files changed, 33 insertions(+), 7 deletions(-)
---
diff --git a/LongoMatch.Core/Common/Exceptions.cs b/LongoMatch.Core/Common/Exceptions.cs
index a07707d..d581200 100644
--- a/LongoMatch.Core/Common/Exceptions.cs
+++ b/LongoMatch.Core/Common/Exceptions.cs
@@ -43,5 +43,22 @@ namespace LongoMatch.Core.Common
                {
                }
        }
+       
+       public class ProjectDeserializationException: Exception
+       {
+               public ProjectDeserializationException (Exception innerException):
+                       base (Catalog.GetString("Project loading failed:") + innerException,
+                             innerException)
+               {
+               }
+       }
+       
+       public class ProjectNotFoundException: Exception
+       {
+               public ProjectNotFoundException (string file):
+                       base (Catalog.GetString("Project file not found:\n") + file)
+               {
+               }
+       }
 }
 
diff --git a/LongoMatch.Services/Services/FileDB.cs b/LongoMatch.Services/Services/FileDB.cs
index 50f9033..768ad9d 100644
--- a/LongoMatch.Services/Services/FileDB.cs
+++ b/LongoMatch.Services/Services/FileDB.cs
@@ -143,15 +143,18 @@ namespace LongoMatch.DB
 
                public Project GetProject (Guid id)
                {
-                       try {
-                               string projectFile = Path.Combine (dbDirPath, id.ToString ());
-                               if (File.Exists (projectFile)) {
+                       Project ret;
+                       string projectFile = Path.Combine (dbDirPath, id.ToString ());
+
+                       if (File.Exists (projectFile)) {
+                               try {
                                        return Serializer.Load<Project> (projectFile);
+                               } catch (Exception ex) {
+                                       throw new ProjectDeserializationException (ex);
                                }
-                       } catch (Exception ex) {
-                               Log.Exception (ex);
+                       } else {
+                               throw new ProjectNotFoundException (projectFile);
                        }
-                       return null;
                }
 
                public bool AddProject (Project project)
diff --git a/LongoMatch.Services/Services/ProjectsManager.cs b/LongoMatch.Services/Services/ProjectsManager.cs
index 55858b5..fdb9c4a 100644
--- a/LongoMatch.Services/Services/ProjectsManager.cs
+++ b/LongoMatch.Services/Services/ProjectsManager.cs
@@ -350,7 +350,13 @@ namespace LongoMatch.Services
                {
                        Project project = null;
                        
-                       project = DB.GetProject (projectID);
+                       try {
+                               project = DB.GetProject (projectID);
+                       } catch (Exception ex) {
+                               Log.Exception (ex);
+                               guiToolkit.ErrorMessage (ex.Message);
+                               return;
+                       }
 
                        if (project.Description.File.FilePath == Constants.FAKE_PROJECT) {
                                /* If it's a fake live project prompt for a video file and


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]