]> git.mxchange.org Git - flightgear.git/commitdiff
- catch exception from readProperties and show dialog
authorcurt <curt>
Thu, 19 Jul 2001 04:51:05 +0000 (04:51 +0000)
committercurt <curt>
Thu, 19 Jul 2001 04:51:05 +0000 (04:51 +0000)
src/Cockpit/hud.cxx
src/Cockpit/panel_io.cxx
src/Main/fg_commands.cxx
src/Main/fg_props.cxx

index 257f1fbb2c3771f35ee54982f0b40c0ecadaa07c..a3aa88452a8d29d50b3470d1a08a29ad0bde03f4 100644 (file)
@@ -21,6 +21,7 @@
 // $Id$
 
 #include <simgear/compiler.h>
+#include <simgear/misc/exception.hxx>
 
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
@@ -644,10 +645,16 @@ int readHud( istream &input )
 
     SGPropertyNode root;
 
-
-    if (!readProperties(input, &root)) {
-        SG_LOG(SG_INPUT, SG_ALERT, "Malformed property list for hud.");
-        return 0;
+    try {
+      readProperties(input, &root);
+    } catch (const sg_io_exception &e) {
+      string message = "Error reading HUD: ";
+      message += e.getMessage();
+      message += "\n at ";
+      message += e.getLocation().asString();
+      SG_LOG(SG_INPUT, SG_ALERT, message);
+      mkDialog(message.c_str());
+      return 0;
     }
   
        
@@ -677,11 +684,18 @@ int readHud( istream &input )
 
 
         SGPropertyNode root2;
-        if (readProperties(path.str(), &root2)) {
-
-            readInstrument(&root2);
-
-        }//if
+       try {
+         readProperties(path.str(), &root2);
+       } catch (const sg_io_exception &e) {
+         string message = "Error reading HUD instrument: ";
+         message += e.getMessage();
+         message += "\n at ";
+         message += e.getLocation().asString();
+         SG_LOG(SG_INPUT, SG_ALERT, message);
+         mkDialog(message.c_str());
+         continue;
+       }
+       readInstrument(&root2);
     }//for loop(i)
 
     return 0;
index af222838ef674a61b6ed323cbefe3e7869b59b4b..456d2d82ff6b41a9b7c7bc2a1ace92a6cb9f2ac4 100644 (file)
@@ -27,6 +27,7 @@
 #endif
 
 #include <simgear/compiler.h>
+#include <simgear/misc/exception.hxx>
 
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/debug/logstream.hxx>
@@ -39,6 +40,8 @@
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 
+#include <GUI/gui.h>
+
 #include "panel.hxx"
 #include "steam.hxx"
 #include "panel_io.hxx"
@@ -760,8 +763,14 @@ fgReadPanel (istream &input)
 {
   SGPropertyNode root;
 
-  if (!readProperties(input, &root)) {
-    SG_LOG( SG_COCKPIT, SG_ALERT, "Malformed property list for panel." );
+  try {
+    readProperties(input, &root);
+  } catch (const sg_io_exception &e) {
+    string message = e.getMessage();
+    message += "\n at ";
+    message += e.getLocation().asString();
+    SG_LOG(SG_INPUT, SG_ALERT, message);
+    mkDialog(message.c_str());
     return 0;
   }
   return readPanel(&root);
@@ -781,8 +790,14 @@ fgReadPanel (const string &relative_path)
   path.append(relative_path);
   SGPropertyNode root;
 
-  if (!readProperties(path.str(), &root)) {
-    SG_LOG( SG_COCKPIT, SG_ALERT, "Malformed property list for panel." );
+  try {
+    readProperties(path.str(), &root);
+  } catch (const sg_io_exception &e) {
+    string message = e.getMessage();
+    message += "\n at ";
+    message += e.getLocation().asString();
+    SG_LOG(SG_INPUT, SG_ALERT, message);
+    mkDialog(message.c_str());
     return 0;
   }
   return readPanel(&root);
index 9072d0f751a175f316e3df752b55d678a043513b..50b6bc9e30432ea90bd4f109a53228cc2680af8c 100644 (file)
@@ -1,6 +1,7 @@
 // fg_commands.cxx - internal FGFS commands.
 
 #include <simgear/compiler.h>
+#include <simgear/misc/exception.hxx>
 
 #include STL_STRING
 #include STL_FSTREAM
@@ -208,13 +209,19 @@ do_preferences_load (const SGPropertyNode * arg, SGCommandState ** state)
   props_path.append(path);
   SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences from "
         << props_path.str());
-  if (!readProperties(props_path.str(), globals->get_props())) {
-    SG_LOG(SG_INPUT, SG_ALERT, "Failed to reread global preferences");
+  try {
+    readProperties(props_path.str(), globals->get_props());
+  } catch (const sg_io_exception &e) {
+    string message = "Error reading global preferences: ";
+    message += e.getMessage();
+    message += "\n at ";
+    message += e.getLocation().asString();
+    SG_LOG(SG_INPUT, SG_ALERT, message);
+    mkDialog(message.c_str());
     return false;
-  } else {
-    SG_LOG(SG_INPUT, SG_INFO, "Successfully read global preferences.");
-    return true;
   }
+  SG_LOG(SG_INPUT, SG_INFO, "Successfully read global preferences.");
+  return true;
 }
 
 
index 6d584b09b2b30488b6abe77aa9055a5505101dc8..cc662d3d51f77046a1b59a4c6ea32c4ce2366fbb 100644 (file)
@@ -24,6 +24,8 @@
 #  include <simgear/compiler.h>
 #endif
 
+#include <simgear/misc/exception.hxx>
+
 #include STL_IOSTREAM
 
 #include <Autopilot/newauto.hxx>
@@ -37,6 +39,8 @@
 #endif
 #include <Objects/matlib.hxx>
 
+#include <GUI/gui.h>
+
 #include "fgfs.hxx"
 #include "fg_props.hxx"
 
@@ -1037,7 +1041,18 @@ fgUpdateProps ()
 bool
 fgSaveFlight (ostream &output)
 {
-  return writeProperties(output, globals->get_props());
+  try {
+    writeProperties(output, globals->get_props());
+  } catch (const sg_io_exception &e) {
+    string message = "Error saving flight: ";
+    message += e.getMessage();
+    message += "\n at ";
+    message += e.getLocation().asString();
+    SG_LOG(SG_INPUT, SG_ALERT, message);
+    mkDialog(message.c_str());
+    return false;
+  }
+  return true;
 }
 
 
@@ -1048,16 +1063,21 @@ bool
 fgLoadFlight (istream &input)
 {
   SGPropertyNode props;
-  if (readProperties(input, &props)) {
-    copyProperties(&props, globals->get_props());
-                               // When loading a flight, make it the
-                               // new initial state.
-    globals->saveInitialState();
-  } else {
-    SG_LOG(SG_INPUT, SG_ALERT, "Error restoring flight; aborted");
+  try {
+    readProperties(input, &props);
+  } catch (const sg_io_exception &e) {
+    string message = "Error reading saved flight: ";
+    message += e.getMessage();
+    message += "\n at ";
+    message += e.getLocation().asString();
+    SG_LOG(SG_INPUT, SG_ALERT, message);
+    mkDialog(message.c_str());
     return false;
   }
-
+  copyProperties(&props, globals->get_props());
+  // When loading a flight, make it the
+  // new initial state.
+  globals->saveInitialState();
   return true;
 }