[zypp-devel] Exception history
(In SVN) Class Exception now offers a history list of message strings. These messages should describe what lead to the exception. The Exceptions message itself is NOT included in the history. History access: /** Iterator pointing to the most recent message. */ HistoryIterator historyBegin() const { return _history.begin(); } /** Iterator pointing behind the last message. */ HistoryIterator historyEnd() const { return _history.end(); } /** Whether the history list is empty. */ bool historyEmpty() const { return _history.empty(); } /** The size of the history list. */ HistorySize historySize() const { return _history.size(); } History maintainance: /** 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 ); Example: Rethrow, remembering an old exception: try { .... } catch( const Exception & olderr_r ) { ZYPP_CAUGHT( olderr_r ) HighLevelException newerr( "Something failed." ); newerr.rember( olderr_r ); ZYPP_THROW( newerr ); } Print exception and history if available: Exception error; dumpRange( ERR << error << endl, err.historyBegin(), err.historyEnd(), "", "History:\n - ", "\n - ", "\n", "" ); Todo: Check and adjust existing code to remember previois Exceptions. -- cu, Michael Andres +------------------------------------------------------------------+ Key fingerprint = 2DFA 5D73 18B1 E7EF A862 27AC 3FB8 9E3A 27C6 B0E4 +------------------------------------------------------------------+ Michael Andres YaST Development ma@novell.com SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nuernberg) Maxfeldstrasse 5, D-90409 Nuernberg, Germany, ++49 (0)911 - 740 53-0 +------------------------------------------------------------------+ -- To unsubscribe, e-mail: zypp-devel+unsubscribe@opensuse.org For additional commands, e-mail: zypp-devel+help@opensuse.org
On Fri, Jul 27, 2007 at 01:46:39PM +0200, Michael Andres wrote:
Class Exception now offers a history list of message strings. These messages should describe what lead to the exception.
Great, this is an important step to better present various installation-time problems in YaST. (Typical one: "Cannot add installation source" actually means "you have unplugged the network cable")
History access: ... History maintainance: ...
OK, I would have probably designed it simpler, using transparent access to a string list, but this is perfectly usable too.
Example:
Rethrow, remembering an old exception:
try { .... } catch( const Exception & olderr_r ) { ZYPP_CAUGHT( olderr_r ) HighLevelException newerr( "Something failed." ); newerr.rember( olderr_r );
Good, in existing code only one line is added. How about operator += as an alias? :-)
ZYPP_THROW( newerr ); }
Print exception and history if available:
Exception error; dumpRange( ERR << error << endl, err.historyBegin(), err.historyEnd(), "", "History:\n - ", "\n - ", "\n", "" );
Well, this is quite cumbersome, a maze of *five* trailing arguments, all alike. Isn't there a shourtcut? Thanks! -- Martin Vidner, YaST developer http://en.opensuse.org/User:Mvidner Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu -- To unsubscribe, e-mail: zypp-devel+unsubscribe@opensuse.org For additional commands, e-mail: zypp-devel+help@opensuse.org
On Fri, Jul 27, Martin Vidner wrote:
Example:
Rethrow, remembering an old exception:
try { .... } catch( const Exception & olderr_r ) { ZYPP_CAUGHT( olderr_r ) HighLevelException newerr( "Something failed." ); newerr.rember( olderr_r );
Good, in existing code only one line is added. How about operator += as an alias? :-)
No. It is more an assignment and not a +. Remember replaces any existing history.
ZYPP_THROW( newerr ); }
Print exception and history if available:
Exception error; dumpRange( ERR << error << endl, err.historyBegin(), err.historyEnd(), "", "History:\n - ", "\n - ", "\n", "" );
Well, this is quite cumbersome, a maze of *five* trailing arguments, all alike. Isn't there a shourtcut?
History is a container of strings, so you can use whatever formater you want. dumpRange is the most flexible we have, but if you're happy with /** The history as string. Empty if \ref historyEmpty. * Otherwise: * \code * History: * - most recent message * - 2nd message * ... * - oldest message * \endcode */ std::string historyAsString() const; So: ERR << error << endl << error.historyAsString();
Thanks! -- Martin Vidner, YaST developer http://en.opensuse.org/User:Mvidner
Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu -- To unsubscribe, e-mail: zypp-devel+unsubscribe@opensuse.org For additional commands, e-mail: zypp-devel+help@opensuse.org
-- cu, Michael Andres +------------------------------------------------------------------+ Key fingerprint = 2DFA 5D73 18B1 E7EF A862 27AC 3FB8 9E3A 27C6 B0E4 +------------------------------------------------------------------+ Michael Andres YaST Development ma@novell.com SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nuernberg) Maxfeldstrasse 5, D-90409 Nuernberg, Germany, ++49 (0)911 - 740 53-0 +------------------------------------------------------------------+ -- To unsubscribe, e-mail: zypp-devel+unsubscribe@opensuse.org For additional commands, e-mail: zypp-devel+help@opensuse.org
On Fri, Jul 27, 2007 at 02:54:08PM +0200, Michael Andres wrote:
newerr.rember( olderr_r );
Good, in existing code only one line is added. How about operator += as an alias? :-)
No. It is more an assignment and not a +. Remember replaces any existing history.
I see, makes sense.
... So: ERR << error << endl << error.historyAsString();
exc.ellent(); -- Martin Vidner, YaST developer http://en.opensuse.org/User:Mvidner Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu -- To unsubscribe, e-mail: zypp-devel+unsubscribe@opensuse.org For additional commands, e-mail: zypp-devel+help@opensuse.org
participants (2)
-
Martin Vidner
-
Michael Andres