/*
* 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
*/
/*! \file
* \brief
- * Declares common exception classes for fatal error handling.
+ * Declares common exception classes and macros for fatal error handling.
*
* \author Teemu Murtola <teemu.murtola@gmail.com>
* \inpublicapi
#include <vector>
#include <boost/exception_ptr.hpp>
+#include <boost/throw_exception.hpp>
#include <boost/exception/errinfo_api_function.hpp>
#include <boost/exception/errinfo_errno.hpp>
#include <boost/exception/exception.hpp>
#include <boost/exception/info.hpp>
-#include <boost/throw_exception.hpp>
namespace gmx
{
typedef std::vector<boost::exception_ptr> NestedExceptionList;
} // namespace internal
-/*! \addtopublicapi
- * \{
- */
+//! \addtogroup module_utility
+//! \{
/*! \brief
* Provides information for Gromacs exception constructors.
{
nested_.push_back(boost::current_exception());
}
+ /*! \brief
+ * Adds the specified exception as a nested exception.
+ *
+ * May be called multiple times; all provided exceptions will be added
+ * in a list of nested exceptions.
+ *
+ * This is equivalent to throwing \p ex and calling
+ * addCurrentExceptionAsNested() in the catch block, but potentially
+ * more efficient.
+ */
+ template <class Exception>
+ void addNested(const Exception &ex)
+ {
+ nested_.push_back(boost::copy_exception(ex));
+ }
private:
std::string reason_;
* -# Because the constructor takes an argument, virtual inheritance would
* complicate any classes that inherit indirectly from this class.
*
- * \ingroup module_utility
+ * \inpublicapi
*/
class GromacsException : public std::exception, public boost::exception
{
/*! \brief
* Exception class for file I/O errors.
*
- * \ingroup module_utility
+ * \inpublicapi
*/
class FileIOError : public GromacsException
{
* Derived classes should be used to indicate the nature of the error instead
* of throwing this class directly.
*
- * \ingroup module_utility
+ * \inpublicapi
*/
class UserInputError : public GromacsException
{
/*! \brief
* Exception class for situations where user input cannot be parsed/understood.
*
- * \ingroup module_utility
+ * \inpublicapi
*/
class InvalidInputError : public UserInputError
{
/*! \brief
* Exception class for situations where user input is inconsistent.
*
- * \ingroup module_utility
+ * \inpublicapi
*/
class InconsistentInputError : public UserInputError
{
/*! \brief
* Exception class for simulation instabilities.
*
- * \ingroup module_utility
+ * \inpublicapi
*/
class SimulationInstabilityError : public GromacsException
{
/*! \brief
* Exception class for internal errors.
*
- * \ingroup module_utility
+ * \inpublicapi
*/
class InternalError : public GromacsException
{
/*! \brief
* Exception class for incorrect use of an API.
*
- * \ingroup module_utility
+ * \inpublicapi
*/
class APIError : public GromacsException
{
/*! \brief
* Exception class for use of an unimplemented feature.
*
- * \ingroup module_utility
+ * \inpublicapi
*/
class NotImplementedError : public APIError
{
{
GMX_THROW(InconsistentUserInput("Negative values not allowed for value"));
}
- * \endcode
+ \endcode
*/
#define GMX_THROW(e) \
BOOST_THROW_EXCEPTION((e))
{
GMX_THROW(FileIOError("Could not open file"), "fopen", errno);
}
- * \endcode
+ \endcode
*/
#define GMX_THROW_WITH_ERRNO(e, syscall, err) \
do { \
/*! \brief
* Formats a standard fatal error message for reporting an exception.
*
- * \param[in] fp File to format the message to.
+ * \param[in] fp %File to format the message to.
* \param[in] ex Exception to format.
*
* Does not throw. If memory allocation fails or some other error occurs
return gmx::processExceptionAtExit(ex);
}
}
- * \endcode
+ \endcode
*/
void printFatalErrorMessage(FILE *fp, const std::exception &ex);
/*! \brief
/*! \brief
* Formats an error message for reporting an exception.
*
- * \param fp File to write the message to.
+ * \param fp %File to write the message to.
* \param[in] ex Exception to format.
* \throws std::bad_alloc if out of memory.
*/
*/
int translateException(const std::exception &ex);
-/*!\}*/
-
-/*! \cond libapi */
-/*! \libinternal \brief
+/*! \brief
* Macro for catching exceptions at C++ -> C boundary.
*
* This macro is intended for uniform handling of exceptions when C++ code is
* behavior if needed.
*
* Usage:
- * \code
+ \code
try
{
// C++ code
}
GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
- * \endcode
- *
- * \inlibraryapi
+ \endcode
*/
#define GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR \
catch (const std::exception &ex) { \
::gmx::printFatalErrorMessage(stderr, ex); \
::std::exit(::gmx::processExceptionAtExit(ex)); \
}
-//! \endcond
+
+//! \}
} // namespace gmx