From 70044757321d8acf5dd7744934cb2965cfbaec89 Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 19 Jul 2001 04:51:05 +0000 Subject: [PATCH] - catch exception from readProperties and show dialog --- src/Cockpit/hud.cxx | 32 +++++++++++++++++++++++--------- src/Cockpit/panel_io.cxx | 23 +++++++++++++++++++---- src/Main/fg_commands.cxx | 17 ++++++++++++----- src/Main/fg_props.cxx | 38 +++++++++++++++++++++++++++++--------- 4 files changed, 83 insertions(+), 27 deletions(-) diff --git a/src/Cockpit/hud.cxx b/src/Cockpit/hud.cxx index 257f1fbb2..a3aa88452 100644 --- a/src/Cockpit/hud.cxx +++ b/src/Cockpit/hud.cxx @@ -21,6 +21,7 @@ // $Id$ #include +#include #ifdef HAVE_CONFIG_H # include @@ -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; diff --git a/src/Cockpit/panel_io.cxx b/src/Cockpit/panel_io.cxx index af222838e..456d2d82f 100644 --- a/src/Cockpit/panel_io.cxx +++ b/src/Cockpit/panel_io.cxx @@ -27,6 +27,7 @@ #endif #include +#include #include #include @@ -39,6 +40,8 @@ #include
#include
+#include + #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); diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 9072d0f75..50b6bc9e3 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -1,6 +1,7 @@ // fg_commands.cxx - internal FGFS commands. #include +#include #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; } diff --git a/src/Main/fg_props.cxx b/src/Main/fg_props.cxx index 6d584b09b..cc662d3d5 100644 --- a/src/Main/fg_props.cxx +++ b/src/Main/fg_props.cxx @@ -24,6 +24,8 @@ # include #endif +#include + #include STL_IOSTREAM #include @@ -37,6 +39,8 @@ #endif #include +#include + #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; } -- 2.39.5