]> git.mxchange.org Git - flightgear.git/commitdiff
Anders GIDENSTAM: catch all exceptions to avoid aborting fgfs after
authormfranz <mfranz>
Wed, 11 Jun 2008 17:16:50 +0000 (17:16 +0000)
committermfranz <mfranz>
Wed, 11 Jun 2008 17:16:50 +0000 (17:16 +0000)
                  commands like "ls .."

src/Network/props.cxx

index 1048a5cc1f116b2dcd1bcd8d64d2dd86491bb57b..66780584994055e504d830948d5d553172d95cb6 100644 (file)
@@ -89,10 +89,9 @@ public:
     void foundTerminator();
 
 private:
-    /**
-     * Return a "Node no found" error message to the client.
-     */
-    void node_not_found_error( const string& node_name );
+    inline void node_not_found_error( const string& s ) const {
+        throw "node '" + s + "' not found";
+    }
 };
 
 /**
@@ -115,19 +114,6 @@ PropsChannel::collectIncomingData( const char* s, int n )
     buffer.append( s, n );
 }
 
-/**
- * 
- */
-void
-PropsChannel::node_not_found_error( const string& node_name )
-{
-    string error = "-ERR Node \"";
-    error += node_name;
-    error += "\" not found.";
-    push( error.c_str() );
-    push( getTerminator() );
-}
-
 // return a human readable form of the value "type"
 static string
 getValueTypeString( const SGPropertyNode *node )
@@ -175,6 +161,7 @@ PropsChannel::foundTerminator()
 
     SGPropertyNode* node = globals->get_props()->getNode( path.c_str() );
 
+    try {
     if (!tokens.empty()) {
        string command = tokens[0];
 
@@ -192,7 +179,6 @@ PropsChannel::foundTerminator()
 
                if (dir == 0) {
                    node_not_found_error( tokens[1] );
-                   goto prompt;
                }
            }
 
@@ -235,16 +221,12 @@ PropsChannel::foundTerminator()
        }
        else if ( command == "cd" ) {
            if (tokens.size() == 2) {
-               try {
-                   SGPropertyNode* child = node->getNode( tokens[1].c_str() );
-                   if ( child ) {
-                       node = child;
-                       path = node->getPath();
-                   } else {
-                       node_not_found_error( tokens[1] );
-                   }
-               } catch (...) {
-                   // Ignore attempt to move past root node with ".."
+               SGPropertyNode* child = node->getNode( tokens[1].c_str() );
+               if ( child ) {
+                   node = child;
+                   path = node->getPath();
+               } else {
+                   node_not_found_error( tokens[1] );
                }
            }
        } else if ( command == "pwd" ) {
@@ -393,7 +375,7 @@ PropsChannel::foundTerminator()
                     push( getTerminator() );
                 }
             }
-       } else if (command == "quit") {
+       } else if ( command == "quit" || command == "exit" ) {
            close();
            shouldDelete();
            return;
@@ -420,8 +402,13 @@ set <var> <val>    set <var> to a new <val>\r\n";
        }
     }
 
- prompt:
-    if (mode == PROMPT) {
+    } catch ( const string& msg ) {
+        string error = "-ERR \"" + msg + "\"";
+        push( error.c_str() );
+        push( getTerminator() );
+    }
+
+    if ( mode == PROMPT ) {
        string prompt = node->getPath();
        if (prompt.empty()) {
            prompt = "/";