Error Handling

- Errors that occur during initialization no longer prevent the
  display of debug info.
This commit is contained in:
Paul Beckingham
2011-07-06 22:52:59 -04:00
parent 5e693b2530
commit 01253f1cdf
3 changed files with 90 additions and 60 deletions

View File

@@ -65,10 +65,13 @@ Context::~Context ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Context::initialize (int argc, const char** argv) int Context::initialize (int argc, const char** argv)
{ {
Timer t ("Context::initialize"); Timer t ("Context::initialize");
int rc = 0;
try
{
// char** argv --> std::vector <std::string> Context::args. // char** argv --> std::vector <std::string> Context::args.
// TODO Handle "cal" case here. // TODO Handle "cal" case here.
args.capture (argc, argv); args.capture (argc, argv);
@@ -144,6 +147,32 @@ void Context::initialize (int argc, const char** argv)
// moment after hook initialization. // moment after hook initialization.
hooks.initialize (); hooks.initialize ();
hooks.trigger ("on-launch"); hooks.trigger ("on-launch");
}
catch (const std::string& error)
{
footnote (error);
rc = 2;
}
catch (...)
{
footnote (STRING_UNKNOWN_ERROR);
rc = 3;
}
// Dump all debug messages, controlled by rc.debug.
if (rc && config.getBoolean ("debug"))
{
std::vector <std::string>::iterator d;
for (d = debugMessages.begin (); d != debugMessages.end (); ++d)
if (color ())
std::cout << colorizeDebug (*d) << "\n";
else
std::cout << *d << "\n";
}
return rc;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@@ -50,7 +50,7 @@ public:
Context (const Context&); Context (const Context&);
Context& operator= (const Context&); Context& operator= (const Context&);
void initialize (int, const char**); // all startup int initialize (int, const char**); // all startup
int run (); int run ();
int dispatch (std::string&); // command handler dispatch int dispatch (std::string&); // command handler dispatch
void shadow (); // shadow file update void shadow (); // shadow file update

View File

@@ -61,7 +61,8 @@ int main (int argc, const char** argv)
try try
{ {
context.initialize (argc, argv); status = context.initialize (argc, argv);
if (status == 0)
status = context.run (); status = context.run ();
} }