/*
* 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"
* 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:
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)
namespace
{
+//! \addtogroup module_utility
+//! \{
+
/*! \brief
* Abstracts actual output from the other logic in exception formatting.
*
* 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
{
* 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
{
}
}
+//! \}
+
} // namespace
void printFatalErrorMessage(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;
}