[gnome-documents/wip/rishi/init-getting-started: 3/6] application: Tie the catch block more tightly to the failure site



commit a19fc738a992a0b73587a72ebde3610d6433d318
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Dec 8 17:13:52 2017 +0100

    application: Tie the catch block more tightly to the failure site
    
    Having a lot of code inside a try statement makes it harder to follow
    the error handling logic. The catch statements are far away from the
    code that can throw an exception, so it is difficult to match them
    together. Let's reduce the size of the try blocks by only using them
    for fallible operations.

 src/application.js |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index d1a9572..7a18387 100644
--- a/src/application.js
+++ b/src/application.js
@@ -153,19 +153,21 @@ var Application = new Lang.Class({
                 function(object, res) {
                     try {
                         let info = object.query_info_finish(res);
-                        this.gettingStartedLocation = file.get_parent();
-
-                        manager.index_file_async(file, null,
-                            function(object, res) {
-                                try {
-                                    manager.index_file_finish(res);
-                                } catch (e) {
-                                    logError(e, 'Error indexing the getting started PDF');
-                                }
-                            });
                     } catch (e) {
                         checkNextFile.apply(this);
+                        return;
                     }
+
+                    this.gettingStartedLocation = file.get_parent();
+
+                    manager.index_file_async(file, null,
+                        function(object, res) {
+                            try {
+                                manager.index_file_finish(res);
+                            } catch (e) {
+                                logError(e, 'Error indexing the getting started PDF');
+                            }
+                        });
                 }));
         }
 


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