From: curt Date: Thu, 19 Jul 2001 04:53:13 +0000 (+0000) Subject: - catch exception from readProperties and exit X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5abff48c8a56fb9b7cb49d86845e51814659bcb1;p=flightgear.git - catch exception from readProperties and exit --- diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 699765c32..e69190122 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -52,6 +52,7 @@ #endif #include +#include #include STL_STRING @@ -215,12 +216,17 @@ bool fgInitConfig ( int argc, char **argv ) { SGPath props_path(globals->get_fg_root()); props_path.append("preferences.xml"); SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences"); - if (!readProperties(props_path.str(), globals->get_props())) { - SG_LOG(SG_INPUT, SG_ALERT, "Failed to read global preferences from " - << props_path.str()); - } else { - SG_LOG(SG_INPUT, SG_INFO, "Finished Reading 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); + exit(2); } + SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences"); // Attempt to locate and parse the various config files in order // from least precidence to greatest precidence diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 93fff76a3..9e77dd783 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -26,6 +26,7 @@ #endif #include +#include /* normans fix */ #if defined(FX) && defined(XMESA) @@ -50,6 +51,8 @@ bool global_fullscreen = true; # include #endif +#include + #include "globals.hxx" #include "fg_init.hxx" #include "fg_props.hxx" @@ -877,10 +880,15 @@ parse_option (const string& arg) parse_flightplan ( arg.substr (14) ); } else if ( arg.find( "--config=" ) == 0 ) { string file = arg.substr(9); - if (!readProperties(file, globals->get_props())) { - SG_LOG(SG_IO, SG_ALERT, - "--config: failed to read properties from " << file); - return FG_OPTIONS_ERROR; + try { + readProperties(file, globals->get_props()); + } catch (const sg_io_exception &e) { + string message = "Error loading config file: "; + message += e.getMessage(); + message += "\n at "; + message += e.getLocation().asString(); + SG_LOG(SG_INPUT, SG_ALERT, message); + exit(2); } } else { SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );