From: david Date: Thu, 4 Apr 2002 17:51:40 +0000 (+0000) Subject: Let exceptions fall through to main, and use cerr to report them (in X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f450e6d9d12e79d5234f597b5cb4db03ecac1a64;p=flightgear.git Let exceptions fall through to main, and use cerr to report them (in case logging is disabled). This way, when people specify a non-existant aircraft or have an error in a custom XML file, they'll get an error report, at least. --- diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 4dae0a6ab..7a3e95a30 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -231,14 +231,7 @@ 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"); - try { - readProperties(props_path.str(), globals->get_props()); - } catch (const sg_exception &e) { - string message = "Error reading global preferences: "; - message += e.getFormattedMessage(); - SG_LOG(SG_INPUT, SG_ALERT, message); - exit(2); - } + readProperties(props_path.str(), globals->get_props()); SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences"); // Read the default aircraft config file. diff --git a/src/Main/main.cxx b/src/Main/main.cxx index c8fc2d538..fc16427a0 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -31,6 +31,11 @@ #endif #include + +#include +SG_USING_STD(cerr); +SG_USING_STD(endl); + #include #include #include @@ -1598,9 +1603,11 @@ int main ( int argc, char **argv ) { try { mainLoop(argc, argv); } catch (sg_throwable &t) { - SG_LOG(SG_GENERAL, SG_ALERT, - "Fatal error: " << t.getFormattedMessage() - << "\n (received from " << t.getOrigin() << ')'); + // We must use cerr rather than + // logging, since logging may be + // disabled. + cerr << "Fatal error: " << t.getFormattedMessage() + << "\n (received from " << t.getOrigin() << ')' << endl; exit(1); } diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 69cb9056f..e6257c4a5 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -942,14 +942,7 @@ parse_option (const string& arg) apath.concat( "-set.xml" ); SG_LOG(SG_INPUT, SG_INFO, "Reading aircraft: " << arg.substr(11) << " from " << apath.str()); - try { - readProperties( apath.str(), globals->get_props() ); - } catch (const sg_exception &e) { - string message = "Error loading aircraft file: "; - message += e.getFormattedMessage(); - SG_LOG(SG_INPUT, SG_ALERT, message); - exit(2); - } + readProperties( apath.str(), globals->get_props() ); } else { SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" ); return FG_OPTIONS_ERROR;