Commit fb78a24c authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Document the code.

parent dc60eb97
...@@ -33,4 +33,19 @@ ...@@ -33,4 +33,19 @@
Bug reporting can be done through the Bug reporting can be done through the
<a href="http://github.com/laas/hpp-util/issues">github ticketing <a href="http://github.com/laas/hpp-util/issues">github ticketing
system</a>. system</a>.
\defgroup macro_exception Preprocessor macros for std exceptions
It eases throwing exceptions built from string stream. You can use equivalently
\code
HPP_THROW(std::runtime_error, "message" << variable);
\endcode
or
\code
HPP_THROW_WITH_LINEINFO(std::runtime_error, "message" << variable);
\endcode
or
\code
throw ::hpp::ExceptionFactory<std::runtime_error>() << "message" << variable << ::hpp::ThrowException();
\endcode
*/ */
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
namespace hpp namespace hpp
{ {
/// \brief Class to ease exception creation. /// \cond
struct ThrowException {}; struct ThrowException {};
template <typename exception> struct ExceptionFactory; template <typename exception> struct ExceptionFactory;
...@@ -32,7 +31,18 @@ namespace hpp ...@@ -32,7 +31,18 @@ namespace hpp
static inline type run(ExceptionFactory<exception>& be, const In& t) { be.ss << t; return be; } static inline type run(ExceptionFactory<exception>& be, const In& t) { be.ss << t; return be; }
}; };
} }
/// \endcond
/// \brief Class to ease exception creation.
///
/// You can use equivalently
/// \code
/// throw ::hpp::ExceptionFactory<std::runtime_error>() << "message" << variable << ::hpp::ThrowException();
/// \endcode
/// or
/// \code
/// HPP_THROW(std::runtime_error>, "message" << variable);
/// \endcode
template <typename exception> template <typename exception>
struct HPP_UTIL_DLLAPI ExceptionFactory struct HPP_UTIL_DLLAPI ExceptionFactory
{ {
...@@ -45,6 +55,7 @@ namespace hpp ...@@ -45,6 +55,7 @@ namespace hpp
} }
}; };
/// \cond
// ---------------------------------------- // ----------------------------------------
// ExceptionFactory - template specialization // ExceptionFactory - template specialization
// ---------------------------------------- // ----------------------------------------
...@@ -56,14 +67,26 @@ namespace hpp ...@@ -56,14 +67,26 @@ namespace hpp
static inline type run(ExceptionFactory<exception>& be, const ThrowException&) { return exception(be.ss.str()); } static inline type run(ExceptionFactory<exception>& be, const ThrowException&) { return exception(be.ss.str()); }
}; };
} }
/// \endcond
} // end of namespace hpp. } // end of namespace hpp.
/// \brief Throw a HPP exception. /// \addtogroup macro_exception
/// \{
/// \brief Throw an exception of type using MSG as a string stream
/// \code
/// HPP_THROW(std::runtime_error>, "message" << variable);
/// \endcode
# define HPP_THROW(TYPE, MSG) \ # define HPP_THROW(TYPE, MSG) \
throw ::hpp::ExceptionFactory<TYPE>() << MSG << ::hpp::ThrowException() throw ::hpp::ExceptionFactory<TYPE>() << MSG << ::hpp::ThrowException()
/// \brief Throw a HPP exception. /// \brief Throw an exception of type using MSG as a string stream
/// \code
/// HPP_THROW_WITH_LINEINFO(std::runtime_error>, "message" << variable);
/// \endcode
# define HPP_THROW_WITH_LINEINFO(TYPE, MSG) \ # define HPP_THROW_WITH_LINEINFO(TYPE, MSG) \
HPP_THROW(TYPE,MSG << " at " << __FILE__ << ":" << __LINE__) HPP_THROW(TYPE,MSG << " at " << __FILE__ << ":" << __LINE__)
/// \}
#endif //! HPP_UTIL_EXCEPTION_FACTORY_HH #endif //! HPP_UTIL_EXCEPTION_FACTORY_HH
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
// //
// See the COPYING file for more information. // See the COPYING file for more information.
/// \file
#ifndef HPP_UTIL_EXCEPTION_HH #ifndef HPP_UTIL_EXCEPTION_HH
# define HPP_UTIL_EXCEPTION_HH # define HPP_UTIL_EXCEPTION_HH
# include <iosfwd> # include <iosfwd>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment