Catch some exceptions during session loading.
authorRobin Gareus <robin@gareus.org>
Thu, 17 Aug 2017 17:28:14 +0000 (19:28 +0200)
committerRobin Gareus <robin@gareus.org>
Thu, 17 Aug 2017 17:28:14 +0000 (19:28 +0200)
libs/ardour/session.cc
libs/ardour/session_state.cc

index de236f61201199b3ee978804d54f7548c735b52c..324e235c72eaaf4406ecca55483f61f92ce7d94b 100644 (file)
@@ -380,8 +380,12 @@ Session::Session (AudioEngine &eng,
                 */
 
                if (!mix_template.empty()) {
-                       if (load_state (_current_snapshot_name)) {
-                               throw SessionException (_("Failed to load template/snapshot state"));
+                       try {
+                               if (load_state (_current_snapshot_name)) {
+                                       throw SessionException (_("Failed to load template/snapshot state"));
+                               }
+                       } catch (PBD::unknown_enumeration& e) {
+                               throw SessionException (_("Failed to parse template/snapshot state"));
                        }
                        store_recent_templates (mix_template);
                }
index ecd8071215df054f1f0dbfbc7c16e5fdcaaec90e..205781b00cec38b5a9b109ea818bc1c7476fc9ce 100644 (file)
@@ -294,8 +294,13 @@ Session::post_engine_init ()
                 */
 
                if (state_tree) {
-                       if (set_state (*state_tree->root(), Stateful::loading_state_version)) {
-                               error << _("Could not set session state from XML") << endmsg;
+                       try {
+                               if (set_state (*state_tree->root(), Stateful::loading_state_version)) {
+                                       error << _("Could not set session state from XML") << endmsg;
+                                       return -4;
+                               }
+                       } catch (PBD::unknown_enumeration& e) {
+                               error << _("Session state: ") << e.what() << endmsg;
                                return -4;
                        }
                } else {
@@ -889,8 +894,14 @@ Session::save_state (string snapshot_name, bool pending, bool switch_to_snapshot
 int
 Session::restore_state (string snapshot_name)
 {
-       if (load_state (snapshot_name) == 0) {
-               set_state (*state_tree->root(), Stateful::loading_state_version);
+       try {
+               if (load_state (snapshot_name) == 0) {
+                       set_state (*state_tree->root(), Stateful::loading_state_version);
+               }
+       } catch (...) {
+               // SessionException
+               // unknown_enumeration
+               return -1;
        }
 
        return 0;
@@ -4547,7 +4558,6 @@ Session::get_info_from_path (const string& xmlpath, float& sample_rate, SampleFo
                return -1;
        }
 
-
        node = node->children;
        while (node != NULL) {
                 if (!strcmp((const char*) node->name, "ProgramVersion")) {
@@ -4571,9 +4581,11 @@ Session::get_info_from_path (const string& xmlpath, float& sample_rate, SampleFo
                                 xmlFree (pv);
                                 xmlChar* val = xmlGetProp (node, (const xmlChar*)"value");
                                 if (val) {
-                                        SampleFormat fmt = (SampleFormat) string_2_enum (string ((const char*)val), fmt);
-                                        data_format = fmt;
-                                        found_data_format = true;
+                                        try {
+                                                SampleFormat fmt = (SampleFormat) string_2_enum (string ((const char*)val), fmt);
+                                                data_format = fmt;
+                                                found_data_format = true;
+                                        } catch (PBD::unknown_enumeration& e) {}
                                 }
                                 xmlFree (val);
                                 break;