summaryrefslogtreecommitdiff
path: root/subversion/bindings/cxxhl/include/svncxxhl/exception.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'subversion/bindings/cxxhl/include/svncxxhl/exception.hpp')
-rw-r--r--subversion/bindings/cxxhl/include/svncxxhl/exception.hpp144
1 files changed, 94 insertions, 50 deletions
diff --git a/subversion/bindings/cxxhl/include/svncxxhl/exception.hpp b/subversion/bindings/cxxhl/include/svncxxhl/exception.hpp
index 3a1b9a0..13e5fbd 100644
--- a/subversion/bindings/cxxhl/include/svncxxhl/exception.hpp
+++ b/subversion/bindings/cxxhl/include/svncxxhl/exception.hpp
@@ -35,9 +35,7 @@
#include "svncxxhl/_compat.hpp"
-// Forward declaration of implementation-specific structure
-struct svn_error_t;
-
+namespace apache {
namespace subversion {
namespace cxxhl {
@@ -45,56 +43,109 @@ namespace compat {} // Announce the compat namespace for shared_ptr lookup
namespace detail {
// Forward declaration of implementation-specific structure
-class error_description;
+class ErrorDescription;
} // namespace detail
-namespace version_1_9_dev {
-
-class error : public std::exception
+/**
+ * Exceptions generated by the C++HL implementation.
+ */
+class InternalError : public std::exception
{
public:
- typedef compat::shared_ptr<error> shared_ptr;
-
- error(const char* description, int error_code);
- error(const char* description, int error_code, shared_ptr nested_error);
+ explicit InternalError(const char* description);
- error(const error& that) throw();
- error& operator=(const error& that) throw();
- virtual ~error() throw();
+ InternalError(const InternalError& that) throw();
+ InternalError& operator= (const InternalError& that) throw();
+ virtual ~InternalError() throw();
/**
- * Returns the error code associated with the exception.
+ * Returns the message associated with this exception object.
*/
- virtual int code() const throw() { return m_errno; }
+ virtual const char* what() const throw();
+
+protected:
+ typedef compat::shared_ptr<detail::ErrorDescription> description_ptr;
+ explicit InternalError(description_ptr description) throw();
+ description_ptr m_description;
+};
+
+/**
+ * Encapsulate a stack of Subversion error codes and messages.
+ */
+class Error : public InternalError
+{
+public:
+ Error(const Error& that) throw();
+ Error& operator=(const Error& that) throw();
+ virtual ~Error() throw();
/**
- * Returns a shared pointer to the nested exception object, if any.
+ * Returns the error code associated with the top-level error that
+ * caused the exception.
*/
- virtual shared_ptr nested() const throw() { return m_nested; }
-
- /// Returns the message associated with this exception object.
- virtual const char* what() const throw();
+ virtual int code() const throw();
/**
* Error message description.
- *
- * The first element of this pair is the error code, the second the
- * associated error message. If the error code is 0, the message
- * describes the location in the source code where the error was
- * generated from.
*/
- typedef std::pair<int, std::string> message;
+ class Message
+ {
+ public:
+ /**
+ * Create a message object given an error code and error message.
+ */
+ Message(int errval, const std::string& message)
+ : m_errno(errval),
+ m_message(message),
+ m_trace(false)
+ {}
+
+ /**
+ * Create a message object given an error code and error message,
+ * and set the flag that tells if this is a debugging traceback entry.
+ */
+ Message(int errval, const std::string& message, bool trace)
+ : m_errno(errval),
+ m_message(message),
+ m_trace(trace)
+ {}
+
+ /**
+ * Return the error code.
+ */
+ int code() const throw() { return m_errno; }
+
+ /**
+ * Return the error message.
+ */
+ const std::string& message() const throw() { return m_message; }
+
+ /**
+ * Return the generic error message associated with the error code.
+ */
+ const char* generic_message() const;
+
+ /**
+ * Check if this message is in fact a debugging traceback entry.
+ */
+ bool trace() const throw() { return m_trace; }
+
+ private:
+ int m_errno;
+ std::string m_message;
+ bool m_trace;
+ };
/**
* The list of messages associated with an error.
*/
- typedef std::vector<message> message_list;
+ typedef std::vector<Message> MessageList;
/**
* Returns the complete list of error messages, including those from
- * nested exceptions.
+ * nested errors.
*/
- virtual message_list messages() const
+ virtual MessageList messages() const
{
return compile_messages(false);
}
@@ -106,39 +157,32 @@ public:
* Traceback is only available if the Subversion libraries were
* compiled with tracing enabled.
*/
- virtual message_list traced_messages() const
+ virtual MessageList traced_messages() const
{
return compile_messages(true);
}
-public:
- /** Used internally by the implementation. */
- static void throw_svn_error(svn_error_t*);
-
protected:
- error(int error_code, detail::error_description* description) throw();
-
-private:
- std::vector<message> compile_messages(bool show_traces) const;
-
- int m_errno; /**< The (SVN or APR) error code. */
- shared_ptr m_nested; /**< Optional pointer to nessted error. */
- /** Error description and trace location information. */
- detail::error_description* m_description;
+ explicit Error(description_ptr description) throw()
+ : InternalError(description)
+ {}
+ MessageList compile_messages(bool show_traces) const;
};
-class cancelled : public error
+/**
+ * Thrown instead of Error when the error chain contains a
+ * @c SVN_ERR_CANCELLED error code.
+ */
+class Cancelled : public Error
{
- friend void error::throw_svn_error(svn_error_t*);
-
protected:
- cancelled(int error_code, detail::error_description* description) throw()
- : error(error_code, description)
+ explicit Cancelled(description_ptr description) throw()
+ : Error(description)
{}
};
-} // namespace version_1_9_dev
} // namespace cxxhl
} // namespace subversion
+} // namespace apache
#endif // SVN_CXXHL_EXCEPTION_HPP