]> git.mxchange.org Git - simgear.git/blobdiff - simgear/structure/SGBinding.cxx
SGPath rename wrapper. Let's see what Win32 makes of it.
[simgear.git] / simgear / structure / SGBinding.cxx
index acd91814c50ebec4cefcbf64b966f2bb51ddd194..836d7abc1364201817df01803040deeb9437a566 100644 (file)
@@ -7,9 +7,17 @@
  * $Id$
  */
 
+#ifdef HAVE_CONFIG_H
+#  include <simgear_config.h>
+#endif
+
 #include <simgear/compiler.h>
 #include "SGBinding.hxx"
 
+#include <simgear/math/SGMath.hxx>
+
+#include <simgear/structure/exception.hxx>
+
 SGBinding::SGBinding()
   : _command(0),
     _arg(new SGPropertyNode),
@@ -27,7 +35,8 @@ SGBinding::SGBinding(const SGPropertyNode* node, SGPropertyNode* root)
 
 SGBinding::~SGBinding()
 {
-  _arg->getParent()->removeChild(_arg->getName(), _arg->getIndex(), false);
+  if(_arg && _arg->getParent())
+    _arg->getParent()->removeChild(_arg->getName(), _arg->getIndex(), false);
 }
 
 void
@@ -41,7 +50,6 @@ SGBinding::read(const SGPropertyNode* node, SGPropertyNode* root)
   if (_command_name.empty()) {
     SG_LOG(SG_INPUT, SG_WARN, "No command supplied for binding.");
     _command = 0;
-    return;
   }
 
   _arg = const_cast<SGPropertyNode*>(node);
@@ -56,9 +64,17 @@ SGBinding::fire () const
       _command = SGCommandMgr::instance()->getCommand(_command_name);
     if (_command == 0) {
       SG_LOG(SG_INPUT, SG_WARN, "No command attached to binding");
-    } else if (!(*_command)(_arg)) {
-      SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command "
-             << _command_name);
+    } else
+    {
+        try {
+            if (!(*_command)(_arg)) {
+                  SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command "
+                         << _command_name);
+            }
+        } catch (sg_exception& e) {
+          SG_LOG(SG_GENERAL, SG_ALERT, "command '" << _command_name << "' failed with exception\n"
+            << "\tmessage:" << e.getMessage() << " (from " << e.getOrigin() << ")");
+        }
     }
   }
 }