#include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/utility.hpp>
+#include <boost/type_traits/is_convertible.hpp>
//#include "Exception.mpp"
///////////////////////////////hh.p////////////////////////////////////////
/** \defgroup exception Exception classes
- All exceptions in senf are derived from senf::Exception. This class adds the possibility to
+ All exceptions in %senf are derived from senf::Exception. This class adds the possibility to
extend the exception description while it is processed:
\code
}
\endcode
- This will add the user information to any senf exception thrown. The Exception is however not a
+ This will add the user information to any %senf exception thrown. The Exception is however not a
stream. If you need to do more extensive formating, either use an intermediate string-stream or
use <a href="http://www.boost.org/libs/format/doc/format.html">Boost.Format</a>:
///////////////////////////////////////////////////////////////////////////
virtual char const * what() const throw();
+ std::string const & message() const;
- template <class Arg>
- Exception & operator<<(Arg const & arg); ///< Extend exception description
- /**< Adds \a arg converted to string to the end of the
- exception description string. This operator allows to
- use Exception instances like streams. The conversion is
- performed using <code>boost::lexical_cast</code> and is
- therefor identical to a streaming operation.
- \see \ref exception */
+ void append(std::string text); ///< Extend exception description
+ /**< Adds \a text to the description text. */
protected:
Exception(std::string const & description = ""); ///< Initialize exception with string
std::string message_;
};
+ template <class Exc, class Arg>
+ typename boost::enable_if< boost::is_convertible<Exc*,Exception*>, Exc & >::type
+ operator<<(Exc const & exc, Arg const & arg); ///< Extend exception description
+ /**< Adds \a arg converted to string to the end of the
+ exception description string. This operator allows to
+ use Exception instances like streams. The conversion is
+ performed using <code>boost::lexical_cast</code> and is
+ therefor identical to a streaming operation.
+ \see \ref exception */
+
+
+# ifdef SENF_DEBUG
+# define _SENF_EXC_DEBUG_ARGS ,char const * file=0,int line=0
+# define _SENF_EXC_DEBUG_ARGS_ND ,char const *file,int line
+# define _SENF_EXC_DEBUG_ARGS_P ,file,line
+# else
+# define _SENF_EXC_DEBUG_ARGS
+# define _SENF_EXC_DEBUG_ARGS_ND
+# define _SENF_EXC_DEBUG_ARGS_P
+# endif
/** \brief Exception handling standard UNIX errors (errno)
throw senf::SystemException();
\endcode
+ From within SENF (<em>and only there because it depends on the \c SENF_DEBUG symbol</em>),
+ SystemException should be thrown using wrapper macros which add additional information to
+ the exception description:
+ \code
+ // Standard usage: Take \c errno from environment
+ SENF_THROW_SYSTEM_EXCEPTION()
+ << " while opening configuration file: " << filename;
+
+ // You may however explicitly specify the errno value
+ throw senf::SystemException("::open()", ENOFILE SENF_EXC_DEBUGINFO)
+ \endcode
+
\ingroup exception
*/
class SystemException : public Exception
///\name Structors and default members
///@{
- explicit SystemException(std::string const & where = "");
- explicit SystemException(int code);
- SystemException(std::string const & where, int code);
+ explicit SystemException(std::string const & descr = "" _SENF_EXC_DEBUG_ARGS);
+ explicit SystemException(int code _SENF_EXC_DEBUG_ARGS);
+ SystemException(std::string const & descr, int code _SENF_EXC_DEBUG_ARGS);
virtual ~SystemException() throw();
///////////////////////////////////////////////////////////////////////////
int errorNumber() const; ///< Error code (\c errno number)
- char const * description() const; ///< Error description (\c strerror() value)
+ char const * errorString() const; ///< Error string (\c strerror() value)
bool anyOf(int c0, int c1=0, int c2=0, int c3=0, int c4=0, int c5=0,
int c6=0, int c7=0, int c8=0, int c9=0);
private:
- void init(std::string const & where, int code);
+ void init(std::string const & descr, int code _SENF_EXC_DEBUG_ARGS_ND);
int code_;
+ std::string what_;
};
+# ifdef SENF_DEBUG
+# define SENF_EXC_DEBUGINFO ,__FILE__,__LINE__
+# else
+# define SENF_EXC_DEBUGINFO
+# endif
+
+# define SENF_THROW_SYSTEM_EXCEPTION(desc) throw SystemException(desc SENF_EXC_DEBUGINFO)
+
}
///////////////////////////////hh.e////////////////////////////////////////