Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / utility / exceptions.cpp
index a5b242721957c5a04b476807036bf11b36c7e8db..952383ffad3c4b86f003be6a2063ed8c422ddb06 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013, by the GROMACS development team, led by
- * David van der Spoel, Berk Hess, Erik Lindahl, and including many
- * others, as listed in the AUTHORS file in the top-level source
- * directory and at http://www.gromacs.org.
+ * Copyright (c) 2011,2012,2013,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
  *
  * GROMACS is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_utility
  */
+#include "gmxpre.h"
+
 #include "exceptions.h"
 
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 
 #include <cstring>
 
 #include <stdexcept>
 #include <typeinfo>
 
-#include <boost/exception/get_error_info.hpp>
 #include <boost/shared_ptr.hpp>
+#include <boost/exception/get_error_info.hpp>
 
-#include "gromacs/legacyheaders/network.h"
-#include "gromacs/legacyheaders/thread_mpi/system_error.h"
+#include "thread_mpi/system_error.h"
+
+#include "gromacs/utility/basenetwork.h"
 #include "gromacs/utility/errorcodes.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/stringutil.h"
@@ -72,6 +73,15 @@ namespace
  * ErrorMessage
  */
 
+/*! \brief
+ * Error message or error context text item.
+ *
+ * Error messages for an exception are represented as a chain of ErrorMessage
+ * objects: the elements at the bottom of the chain (with no children) is the
+ * error message, and other elements are the context strings added.
+ *
+ * \ingroup module_utility
+ */
 class ErrorMessage
 {
     public:
@@ -166,11 +176,15 @@ GromacsException::GromacsException(const ExceptionInitializer &details)
 const char *GromacsException::what() const throw()
 {
     const ErrorMessage *msg = boost::get_error_info<errinfo_message>(*this);
-    while (msg != NULL && msg->isContext())
+    if (msg == NULL)
+    {
+        return "No reason provided";
+    }
+    while (msg->isContext())
     {
         msg = &msg->child();
     }
-    return msg != NULL ? msg->text().c_str() : "No reason provided";
+    return msg->text().c_str();
 }
 
 void GromacsException::prependContext(const std::string &context)
@@ -227,6 +241,9 @@ int NotImplementedError::errorCode() const
 namespace
 {
 
+//! \addtogroup module_utility
+//! \{
+
 /*! \brief
  * Abstracts actual output from the other logic in exception formatting.
  *
@@ -234,7 +251,7 @@ namespace
  * formatExceptionMessageInternal(), and is responsible for composing the
  * output.  This allows using the same implementation of interpreting the
  * exceptions while still supporting output to different formats (e.g., to a
- * string or to stderr).
+ * string or to \c stderr).
  */
 class MessageWriterInterface
 {
@@ -263,7 +280,7 @@ class MessageWriterInterface
  * Exception information writer for cases where exceptions should be avoided.
  *
  * Formats the messages into the provided FILE handle without checking for
- * errors in fprintf() calls.
+ * errors in std::fprintf() calls.
  */
 class MessageWriterFileNoThrow : public MessageWriterInterface
 {
@@ -421,6 +438,8 @@ void formatExceptionMessageInternal(MessageWriterInterface *writer,
     }
 }
 
+//! \}
+
 }   // namespace
 
 void printFatalErrorMessage(FILE *fp, const std::exception &ex)
@@ -495,13 +514,13 @@ void formatExceptionMessageToFile(FILE *fp, const std::exception &ex)
     formatExceptionMessageInternal(&writer, ex, 0);
 }
 
-int processExceptionAtExit(const std::exception &/*ex*/)
+int processExceptionAtExit(const std::exception & /*ex*/)
 {
     int returnCode = 1;
 #ifdef GMX_LIB_MPI
     // TODO: Consider moving the output done in gmx_abort() into the message
     // printing routine above, so that this could become a simple MPI_Abort().
-    gmx_abort(gmx_node_rank(), gmx_node_num(), returnCode);
+    gmx_abort(returnCode);
 #endif
     return returnCode;
 }