aboutsummaryrefslogtreecommitdiff
path: root/paludis/exception.hh
diff options
context:
space:
mode:
Diffstat (limited to 'paludis/exception.hh')
-rw-r--r--paludis/exception.hh55
1 files changed, 52 insertions, 3 deletions
diff --git a/paludis/exception.hh b/paludis/exception.hh
index b6b9003..f3dbb09 100644
--- a/paludis/exception.hh
+++ b/paludis/exception.hh
@@ -21,19 +21,25 @@
#define PALUDIS_GUARD_PALUDIS_EXCEPTION_HH 1
#include <paludis/attributes.hh>
+#include <paludis/stringify.hh>
#include <string>
#include <exception>
#include <libebt/libebt.hh>
/** \file
- * Declaration for the Exception base class.
+ * Declaration for the Exception base class, the InternalError exception
+ * class and related utilities.
+ *
+ * \ingroup Exception
*/
namespace paludis
{
/**
* Context tag for libebt.
+ *
+ * \ingroup Exception
*/
struct PaludisBacktraceTag
{
@@ -41,14 +47,19 @@ namespace paludis
/**
* Backtrace context class.
+ *
+ * \ingroup Exception
*/
typedef libebt::BacktraceContext<PaludisBacktraceTag> Context;
/**
* Base exception class.
+ *
+ * \ingroup Exception
*/
- class Exception : public std::exception,
- public libebt::Backtraceable<PaludisBacktraceTag>
+ class Exception :
+ public std::exception,
+ public libebt::Backtraceable<PaludisBacktraceTag>
{
private:
const std::string _message;
@@ -70,6 +81,44 @@ namespace paludis
*/
const std::string & message() const throw () PALUDIS_ATTRIBUTE((nothrow));
};
+
+ /**
+ * An InternalError is an Exception that is thrown if something that is
+ * never supposed to happen happens.
+ *
+ * \ingroup Exception
+ */
+ class InternalError : public Exception
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * \param function Should be set to the PALUDIS_HERE macro.
+ *
+ * \param message A short message.
+ */
+ InternalError(const std::string & where, const std::string & message) throw ();
+
+ /**
+ * Constructor, with no message (deprecated).
+ *
+ * \param function Should be set to the PALUDIS_HERE macro.
+ *
+ * \deprecated Use paludis::InternalError::InternalError(const char * const,
+ * const std::string &) instead.
+ */
+ InternalError(const std::string & where) throw () PALUDIS_ATTRIBUTE((deprecated));
+ };
}
+/** \def PALUDIS_HERE
+ * Expands to the current function name, file and line, for use with
+ * paludis::InternalError.
+ *
+ * \ingroup Exception
+ */
+#define PALUDIS_HERE (paludis::stringify(__PRETTY_FUNCTION__) + " at " + \
+ paludis::stringify(__FILE__) + ":" + paludis::stringify(__LINE__))
+
#endif