From 5fa38f5b19169c913114bdd2a0ed5a90f1e4b664 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Fri, 27 Jul 2007 10:12:30 +0000 Subject: [PATCH] add message history to Exception --- zypp/base/Exception.cc | 14 ++++++++++++++ zypp/base/Exception.h | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/zypp/base/Exception.cc b/zypp/base/Exception.cc index bde0eed..8b745d4 100644 --- a/zypp/base/Exception.cc +++ b/zypp/base/Exception.cc @@ -67,6 +67,20 @@ namespace zypp return _(str.str().c_str()); } + void Exception::remember( const Exception & old_r ) + { + if ( &old_r != this ) // no self-remember + { + History newh( old_r._history.begin(), old_r._history.end() ); + newh.push_front( old_r.asUserString() ); + _history.swap( newh ); + } + } + + void Exception::addHistory( const std::string & msg_r ) + { + _history.push_front( msg_r ); + } std::ostream & Exception::dumpOn( std::ostream & str ) const { return str << _msg; } diff --git a/zypp/base/Exception.h b/zypp/base/Exception.h index e9c3253..71bfd30 100644 --- a/zypp/base/Exception.h +++ b/zypp/base/Exception.h @@ -14,6 +14,7 @@ #include #include +#include #include /////////////////////////////////////////////////////////////////// @@ -118,6 +119,9 @@ namespace zypp public: typedef exception_detail::CodeLocation CodeLocation; + typedef std::list History; + typedef History::const_iterator HistoryIterator; + typedef History::size_type HistorySize; /** Default ctor. * Use \ref ZYPP_THROW to throw exceptions. @@ -154,6 +158,39 @@ namespace zypp /** Translated error message as string suitable for the user. */ std::string asUserString() const; + public: + /** \name History list of message strings. + * Maintain a simple list of individual error messages, that lead + * to this Exception. The Exceptions message itself is not included + * in the history. The History list stores the most recent message + * fist. + */ + //@{ + + /** Store an other Exception as history. */ + void remember( const Exception & old_r ); + + /** Add some message text to the history. */ + void addHistory( const std::string & msg_r ); + + /** */ + HistoryIterator historyBegin() const + { return _history.begin(); } + + /** */ + HistoryIterator historyEnd() const + { return _history.end(); } + + /** */ + bool historyEmpty() const + { return _history.empty(); } + + /** */ + HistorySize historySize() const + { return _history.size(); } + + //@} + protected: /** Overload this to print a proper error message. */ @@ -174,7 +211,8 @@ namespace zypp private: mutable CodeLocation _where; - std::string _msg; + std::string _msg; + History _history; /** Return message string. */ virtual const char * what() const throw() -- 2.7.4