From: Michael Andres Date: Thu, 21 Oct 2010 11:01:00 +0000 (+0200) Subject: Exception: add ctor taking a message and an exception to remember as history X-Git-Tag: 8.7.1~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e6ee8639ecaba23f883ae0b205a9c4f5566ca03a;p=platform%2Fupstream%2Flibzypp.git Exception: add ctor taking a message and an exception to remember as history --- diff --git a/zypp/PluginScriptException.h b/zypp/PluginScriptException.h index 787943780..bf8c8cfe9 100644 --- a/zypp/PluginScriptException.h +++ b/zypp/PluginScriptException.h @@ -57,6 +57,7 @@ namespace zypp /** Timeout while receiving data. */ declException( PluginScriptReceiveTimeout, PluginScriptTimeout ); +#undef declException ///////////////////////////////////////////////////////////////// } // namespace zypp diff --git a/zypp/base/Exception.cc b/zypp/base/Exception.cc index dfd62e39f..86f7b51d2 100644 --- a/zypp/base/Exception.cc +++ b/zypp/base/Exception.cc @@ -49,6 +49,10 @@ namespace zypp : _msg( msg_r ) {} + Exception::Exception( const std::string & msg_r, const Exception & history_r ) + : _msg( msg_r ) + { remember( history_r ); } + Exception::~Exception() throw() {} @@ -130,7 +134,7 @@ namespace zypp void Exception::log( const Exception & excpt_r, const CodeLocation & where_r, const char *const prefix_r ) { - INT << where_r << " " << prefix_r << " " << excpt_r << endl; + INT << where_r << " " << prefix_r << " " << excpt_r.asUserHistory() << endl; } ///////////////////////////////////////////////////////////////// diff --git a/zypp/base/Exception.h b/zypp/base/Exception.h index 89db2d503..4d0f5be63 100644 --- a/zypp/base/Exception.h +++ b/zypp/base/Exception.h @@ -160,6 +160,12 @@ namespace zypp */ Exception( const std::string & msg_r ); + /** Ctor taking a message and an exception to remember as history + * \see \ref remember + * Use \ref ZYPP_THROW to throw exceptions. + */ + Exception( const std::string & msg_r, const Exception & history_r ); + /** Dtor. */ virtual ~Exception() throw(); diff --git a/zypp/base/UserRequestException.cc b/zypp/base/UserRequestException.cc index 2165889f5..707bafb94 100644 --- a/zypp/base/UserRequestException.cc +++ b/zypp/base/UserRequestException.cc @@ -29,10 +29,18 @@ namespace zypp : Exception( msg_r ), _kind( UNSPECIFIED ) {} + UserRequestException::UserRequestException( const std::string & msg_r, const Exception & history_r ) + : Exception( msg_r, history_r ), _kind( UNSPECIFIED ) + {} + UserRequestException::UserRequestException( Kind kind_r, const std::string & msg_r ) : Exception( msg_r ), _kind( kind_r ) {} + UserRequestException::UserRequestException( Kind kind_r, const std::string & msg_r, const Exception & history_r ) + : Exception( msg_r, history_r ), _kind( kind_r ) + {} + /////////////////////////////////////////////////////////////////// // // METHOD NAME : UserRequestException::dumpOn diff --git a/zypp/base/UserRequestException.h b/zypp/base/UserRequestException.h index a3e9d045f..c4103b24a 100644 --- a/zypp/base/UserRequestException.h +++ b/zypp/base/UserRequestException.h @@ -68,8 +68,10 @@ namespace zypp public: explicit UserRequestException( const std::string & msg_r = std::string() ); + UserRequestException( const std::string & msg_r, const Exception & history_r ); explicit UserRequestException( Kind kind_r, const std::string & msg_r = std::string() ); + UserRequestException( Kind kind_r, const std::string & msg_r, const Exception & history_r ); public: Kind kind() const { return _kind; } @@ -80,37 +82,24 @@ namespace zypp }; /////////////////////////////////////////////////////////////////// - struct IgnoreRequestException : public UserRequestException - { - explicit - IgnoreRequestException( const std::string & msg_r = std::string() ) - : UserRequestException( IGNORE, msg_r ) - {} - }; + /** Convenience macro to declare more specific PluginScriptExceptions. */ +#define declException( EXCP, KIND ) \ + struct EXCP : public UserRequestException { \ + explicit \ + EXCP( const std::string & msg_r = std::string() ) \ + : UserRequestException( KIND, msg_r ) \ + {} \ + EXCP( const std::string & msg_r, const Exception & history_r ) \ + : UserRequestException( KIND, msg_r, history_r ) \ + {} \ + } - struct SkipRequestException : public UserRequestException - { - explicit - SkipRequestException( const std::string & msg_r = std::string() ) - : UserRequestException( SKIP, msg_r ) - {} - }; + declException( IgnoreRequestException, IGNORE ); + declException( SkipRequestException, SKIP ); + declException( RetryRequestException, RETRY ); + declException( AbortRequestException, ABORT ); - struct RetryRequestException : public UserRequestException - { - explicit - RetryRequestException( const std::string & msg_r = std::string() ) - : UserRequestException( RETRY, msg_r ) - {} - }; - - struct AbortRequestException : public UserRequestException - { - explicit - AbortRequestException( const std::string & msg_r = std::string() ) - : UserRequestException( ABORT, msg_r ) - {} - }; +#undef declException ///////////////////////////////////////////////////////////////// } // namespace zypp