1
0
Fork 0

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.
This commit is contained in:
david 2002-04-04 17:51:40 +00:00
parent 8ac5a5327e
commit f450e6d9d1
3 changed files with 12 additions and 19 deletions

View file

@ -231,14 +231,7 @@ bool fgInitConfig ( int argc, char **argv ) {
SGPath props_path(globals->get_fg_root()); SGPath props_path(globals->get_fg_root());
props_path.append("preferences.xml"); props_path.append("preferences.xml");
SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences"); SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
try { readProperties(props_path.str(), globals->get_props());
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);
}
SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences"); SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
// Read the default aircraft config file. // Read the default aircraft config file.

View file

@ -31,6 +31,11 @@
#endif #endif
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <iostream>
SG_USING_STD(cerr);
SG_USING_STD(endl);
#include <simgear/misc/exception.hxx> #include <simgear/misc/exception.hxx>
#include <simgear/ephemeris/ephemeris.hxx> #include <simgear/ephemeris/ephemeris.hxx>
#include <simgear/route/route.hxx> #include <simgear/route/route.hxx>
@ -1598,9 +1603,11 @@ int main ( int argc, char **argv ) {
try { try {
mainLoop(argc, argv); mainLoop(argc, argv);
} catch (sg_throwable &t) { } catch (sg_throwable &t) {
SG_LOG(SG_GENERAL, SG_ALERT, // We must use cerr rather than
"Fatal error: " << t.getFormattedMessage() // logging, since logging may be
<< "\n (received from " << t.getOrigin() << ')'); // disabled.
cerr << "Fatal error: " << t.getFormattedMessage()
<< "\n (received from " << t.getOrigin() << ')' << endl;
exit(1); exit(1);
} }

View file

@ -942,14 +942,7 @@ parse_option (const string& arg)
apath.concat( "-set.xml" ); apath.concat( "-set.xml" );
SG_LOG(SG_INPUT, SG_INFO, "Reading aircraft: " << arg.substr(11) SG_LOG(SG_INPUT, SG_INFO, "Reading aircraft: " << arg.substr(11)
<< " from " << apath.str()); << " from " << apath.str());
try { readProperties( apath.str(), globals->get_props() );
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);
}
} else { } else {
SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" ); SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
return FG_OPTIONS_ERROR; return FG_OPTIONS_ERROR;