Exception: add ctor taking a message and an exception to remember as history
authorMichael Andres <ma@suse.de>
Thu, 21 Oct 2010 11:01:00 +0000 (13:01 +0200)
committerMichael Andres <ma@suse.de>
Thu, 21 Oct 2010 11:01:00 +0000 (13:01 +0200)
zypp/PluginScriptException.h
zypp/base/Exception.cc
zypp/base/Exception.h
zypp/base/UserRequestException.cc
zypp/base/UserRequestException.h

index 787943780da411998e8ceab27cae544b89356a2c..bf8c8cfe98a62195fbcdfdc848d6c03aa57c733d 100644 (file)
@@ -57,6 +57,7 @@ namespace zypp
   /** Timeout while receiving data. */
   declException( PluginScriptReceiveTimeout, PluginScriptTimeout );
 
+#undef declException
 
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
index dfd62e39f9405895598654dbe21170e4bf27f20c..86f7b51d2cac5241b2182200a072b8a1a7c245ba 100644 (file)
@@ -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;
   }
 
   /////////////////////////////////////////////////////////////////
index 89db2d503aa88b66bbb9ede56ccf000baf05f8e2..4d0f5be632e90c75e9f30527d585cfa6ca5fbbd9 100644 (file)
@@ -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();
 
index 2165889f51d9b782f05e3aafeae7bd6c23e24dd6..707bafb9430a457e2c8dcc6c80d87f2c31ad9e4e 100644 (file)
@@ -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
index a3e9d045fc0591ab40b4d205c9e5096340c11035..c4103b24ab9d2161f07d571f4ad40099dc7f1d8b 100644 (file)
@@ -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