X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2Fcommands.cxx;h=6f6db1c661bad0544adb28150c0e946b22684a0c;hb=200df49d6e2d8896e1deaa6da7af5b4a91058a4f;hp=b2391e3ba7f1cff7986f8eacf5364e985739ee56;hpb=9cbbe5559844317f44744788ddb308101a1e75e9;p=simgear.git diff --git a/simgear/structure/commands.cxx b/simgear/structure/commands.cxx index b2391e3b..6f6db1c6 100644 --- a/simgear/structure/commands.cxx +++ b/simgear/structure/commands.cxx @@ -17,7 +17,8 @@ #include "commands.hxx" #include - +#include +#include //////////////////////////////////////////////////////////////////////// @@ -53,22 +54,22 @@ SGCommandMgr::instance() } void -SGCommandMgr::addCommand (const string &name, command_t command) +SGCommandMgr::addCommand (const std::string &name, command_t command) { _commands[name] = command; } SGCommandMgr::command_t -SGCommandMgr::getCommand (const string &name) const +SGCommandMgr::getCommand (const std::string &name) const { const command_map::const_iterator it = _commands.find(name); return (it != _commands.end() ? it->second : 0); } -vector +string_list SGCommandMgr::getCommandNames () const { - vector names; + string_list names; command_map::const_iterator it = _commands.begin(); command_map::const_iterator last = _commands.end(); while (it != last) { @@ -79,13 +80,20 @@ SGCommandMgr::getCommandNames () const } bool -SGCommandMgr::execute (const string &name, const SGPropertyNode * arg) const +SGCommandMgr::execute (const std::string &name, const SGPropertyNode * arg) const { command_t command = getCommand(name); if (command == 0) return false; - else + + + try { return (*command)(arg); + } catch (sg_exception& e) { + SG_LOG(SG_GENERAL, SG_ALERT, "command '" << name << "' failed with exception\n" + << "\tmessage:" << e.getMessage() << " (from " << e.getOrigin() << ")"); + return false; + } } // end of commands.cxx