Improve selection error messages (use exceptions)
[alexxy/gromacs.git] / src / gromacs / utility / exceptions.cpp
index 952383ffad3c4b86f003be6a2063ed8c422ddb06..14fe155e434e892d378d644b6eecefa24b8e4377 100644 (file)
@@ -381,6 +381,7 @@ void formatExceptionMessageInternal(MessageWriterInterface *writer,
         //                           funcPtr != NULL ? *funcPtr : "");
         // }
 
+        bool                bAnythingWritten = false;
         // TODO: Remove duplicate context if present in multiple nested exceptions.
         const ErrorMessage *msg = boost::get_error_info<errinfo_message>(*boostEx);
         if (msg != NULL)
@@ -394,11 +395,13 @@ void formatExceptionMessageInternal(MessageWriterInterface *writer,
             if (msg != NULL && !msg->text().empty())
             {
                 writer->writeLine(msg->text().c_str(), indent*2);
+                bAnythingWritten = true;
             }
         }
         else
         {
             writer->writeLine(ex.what(), indent*2);
+            bAnythingWritten = true;
         }
 
         const int *errorNumber
@@ -410,6 +413,7 @@ void formatExceptionMessageInternal(MessageWriterInterface *writer,
             writer->writeErrNoInfo(*errorNumber,
                                    funcName != NULL ? *funcName : NULL,
                                    (indent+1)*2);
+            bAnythingWritten = true;
         }
 
         // TODO: Treat also boost::nested_exception (not currently used, though)
@@ -427,7 +431,8 @@ void formatExceptionMessageInternal(MessageWriterInterface *writer,
                 }
                 catch (const std::exception &nestedEx)
                 {
-                    formatExceptionMessageInternal(writer, nestedEx, indent + 1);
+                    const int newIndent = indent + (bAnythingWritten ? 1 : 0);
+                    formatExceptionMessageInternal(writer, nestedEx, newIndent);
                 }
             }
         }