libzypp  13.10.6
zypp::Exception Class Reference

Base class for Exception. More...

#include <Exception.h>

Inheritance diagram for zypp::Exception:
zypp::BadKeyException zypp::base::ZYppLockedException zypp::CheckSumException zypp::DateFormatException zypp::FileCheckException zypp::KeyRingException zypp::MatchException zypp::media::MediaException zypp::parser::ParseException zypp::PluginFrameException zypp::PluginScriptException zypp::repo::RepoException zypp::repo::ServiceException zypp::target::hal::HalException zypp::target::hal::NoHalException zypp::target::rpm::RpmException zypp::target::TargetException zypp::thread::MutexException zypp::url::UrlException zypp::UserRequestException zypp::xml::ParseDefException zypp::ZYppFactoryException

Public Types

typedef
exception_detail::CodeLocation 
CodeLocation
 
typedef std::list< std::string > History
 
typedef History::const_iterator HistoryIterator
 
typedef History::size_type HistorySize
 

Public Member Functions

 Exception ()
 Default ctor. More...
 
 Exception (const std::string &msg_r)
 Ctor taking a message. More...
 
 Exception (const std::string &msg_r, const Exception &history_r)
 Ctor taking a message and an exception to remember as history. More...
 
virtual ~Exception () throw ()
 Dtor. More...
 
const CodeLocationwhere () const
 Return CodeLocation. More...
 
void relocate (const CodeLocation &where_r) const
 Exchange location on rethrow. More...
 
const std::string & msg () const
 Return the message string provided to the ctor. More...
 
std::string asString () const
 Error message provided by dumpOn as string. More...
 
std::string asUserString () const
 Translated error message as string suitable for the user. More...
 
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.

void remember (const Exception &old_r)
 Store an other Exception as history. More...
 
void addHistory (const std::string &msg_r)
 Add some message text to the history. More...
 
HistoryIterator historyBegin () const
 Iterator pointing to the most recent message. More...
 
HistoryIterator historyEnd () const
 Iterator pointing behind the last message. More...
 
bool historyEmpty () const
 Whether the history list is empty. More...
 
HistorySize historySize () const
 The size of the history list. More...
 
std::string historyAsString () const
 The history as string. More...
 
std::string asUserHistory () const
 A single (multiline) string composed of asUserString and historyAsString. More...
 

Static Public Member Functions

static std::string strErrno (int errno_r)
 Make a string from errno_r. More...
 
static std::string strErrno (int errno_r, const std::string &msg_r)
 Make a string from errno_r and msg_r. More...
 
static void log (const Exception &excpt_r, const CodeLocation &where_r, const char *const prefix_r)
 Drop a logline on throw, catch or rethrow. More...
 

Protected Member Functions

virtual std::ostream & dumpOn (std::ostream &str) const
 Overload this to print a proper error message. More...
 

Private Member Functions

virtual const char * what () const throw ()
 Return message string. More...
 
std::ostream & dumpError (std::ostream &str) const
 Called by std::ostream & operator<<. More...
 

Private Attributes

CodeLocation _where
 
std::string _msg
 
History _history
 

Friends

std::ostream & operator<< (std::ostream &str, const Exception &obj)
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &str, const Exception &obj)
 

Detailed Description

Base class for Exception.

Exception offers to store a message string passed to the ctor. Derived classes may provide additional information. Overload dumpOn to provide a proper error text.

The use of these macros is not mandatory. but ZYPP_THROW and ZYPP_RETHROW will adjust the code location information stored in the Exception. All three macros will drop a line in the logfile.

* 43 try
* 44 {
* 45 try
* 46 {
* 47 ZYPP_THROW( Exception("Something bad happened.") );
* 48 }
* 49 catch ( Exception & excpt )
* 50 {
* 51 ZYPP_RETHROW( excpt );
* 52 }
* 53
* 54 }
* 55 catch ( Exception & excpt )
* 56 {
* 57 ZYPP_CAUGHT( excpt );
* 58 }
*

The above produces the following log lines:

* Main.cc(main):47 THROW: Main.cc(main):47: Something bad happened.
* Main.cc(main):51 RETHROW: Main.cc(main):47: Something bad happened.
* Main.cc(main):57 CAUGHT: Main.cc(main):51: Something bad happened.
*

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.

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 an Exception followed by it's history if available:

* ERR << error << endl << error.historyAsString();
*
Todo:
That's a draft to have a common way of throwing exceptions. Most probabely we'll finally use blocxx exceptions. Here, but not in the remaining code of zypp. If we can we should try to wrap the blocxx macros and typedef the classes in here.

Definition at line 143 of file Exception.h.

Member Typedef Documentation

typedef std::list<std::string> zypp::Exception::History

Definition at line 149 of file Exception.h.

typedef History::const_iterator zypp::Exception::HistoryIterator

Definition at line 150 of file Exception.h.

typedef History::size_type zypp::Exception::HistorySize

Definition at line 151 of file Exception.h.

Constructor & Destructor Documentation

zypp::Exception::Exception ( )

Default ctor.

Use ZYPP_THROW macros to throw exceptions.

Definition at line 45 of file Exception.cc.

zypp::Exception::Exception ( const std::string &  msg_r)

Ctor taking a message.

Use ZYPP_THROW macros to throw exceptions.

Definition at line 48 of file Exception.cc.

zypp::Exception::Exception ( const std::string &  msg_r,
const Exception history_r 
)

Ctor taking a message and an exception to remember as history.

See Also
remember Use ZYPP_THROW macros to throw exceptions.

Definition at line 52 of file Exception.cc.

zypp::Exception::~Exception ( )
throw (
)
virtual

Dtor.

Definition at line 56 of file Exception.cc.

Member Function Documentation

const CodeLocation& zypp::Exception::where ( ) const
inline

Return CodeLocation.

Definition at line 173 of file Exception.h.

void zypp::Exception::relocate ( const CodeLocation where_r) const
inline

Exchange location on rethrow.

Definition at line 177 of file Exception.h.

const std::string& zypp::Exception::msg ( ) const
inline

Return the message string provided to the ctor.

Note
This is not necessarily the complete error message. The whole error message is provided by asString or dumpOn.

Definition at line 185 of file Exception.h.

std::string zypp::Exception::asString ( ) const

Error message provided by dumpOn as string.

Definition at line 59 of file Exception.cc.

std::string zypp::Exception::asUserString ( ) const

Translated error message as string suitable for the user.

See Also
asUserStringHistory

Definition at line 66 of file Exception.cc.

void zypp::Exception::remember ( const Exception old_r)

Store an other Exception as history.

Definition at line 89 of file Exception.cc.

void zypp::Exception::addHistory ( const std::string &  msg_r)

Add some message text to the history.

Definition at line 99 of file Exception.cc.

HistoryIterator zypp::Exception::historyBegin ( ) const
inline

Iterator pointing to the most recent message.

Definition at line 212 of file Exception.h.

HistoryIterator zypp::Exception::historyEnd ( ) const
inline

Iterator pointing behind the last message.

Definition at line 216 of file Exception.h.

bool zypp::Exception::historyEmpty ( ) const
inline

Whether the history list is empty.

Definition at line 220 of file Exception.h.

HistorySize zypp::Exception::historySize ( ) const
inline

The size of the history list.

Definition at line 224 of file Exception.h.

std::string zypp::Exception::historyAsString ( ) const

The history as string.

Empty if historyEmpty. Otherwise:

* - most recent message
* - 2nd message
* ...
* - oldest message
*

Definition at line 104 of file Exception.cc.

std::string zypp::Exception::asUserHistory ( ) const

A single (multiline) string composed of asUserString and historyAsString.

Definition at line 75 of file Exception.cc.

std::ostream & zypp::Exception::dumpOn ( std::ostream &  str) const
protectedvirtual

Overload this to print a proper error message.

Reimplemented in zypp::media::MediaNoLoopDeviceException, zypp::media::MediaBadCAException, zypp::media::MediaTemporaryProblemException, zypp::media::MediaTimeoutException, zypp::media::MediaForbiddenException, zypp::media::MediaUnauthorizedException, zypp::media::MediaNotEjectedException, zypp::media::MediaIsSharedException, zypp::media::MediaNotDesiredException, zypp::media::MediaCurlSetOptException, zypp::media::MediaCurlException, zypp::media::MediaNotSupportedException, zypp::media::MediaUnsupportedUrlSchemeException, zypp::media::MediaBadUrlEmptyDestinationException, zypp::media::MediaBadUrlEmptyFilesystemException, zypp::media::MediaBadUrlEmptyHostException, zypp::media::MediaBadUrlException, zypp::media::MediaNotADirException, zypp::media::MediaNotAFileException, zypp::target::rpm::RpmNullDatabaseException, zypp::media::MediaSystemException, zypp::target::rpm::RpmDbConvertException, zypp::media::MediaCurlInitException, zypp::target::rpm::RpmDbNotOpenException, zypp::media::MediaBadAttachPointException, zypp::target::rpm::RpmDbAlreadyOpenException, zypp::repo::ServiceException, zypp::media::MediaNotAttachedException, zypp::target::rpm::RpmDbOpenException, zypp::media::MediaWriteException, zypp::media::MediaFileNotFoundException, zypp::target::rpm::RpmInitException, zypp::media::MediaNotOpenException, zypp::target::rpm::RpmSubprocessException, zypp::media::MediaBadFilenameException, zypp::target::rpm::RpmAccessBlockedException, zypp::media::MediaUnmountException, zypp::target::rpm::RpmInvalidRootException, zypp::target::hal::HalException, zypp::media::MediaMountException, zypp::UserRequestException, zypp::target::TargetAbortedException, zypp::repo::RepoException, and zypp::parser::ParseException.

Definition at line 114 of file Exception.cc.

std::string zypp::Exception::strErrno ( int  errno_r)
static

Make a string from errno_r.

Definition at line 124 of file Exception.cc.

std::string zypp::Exception::strErrno ( int  errno_r,
const std::string &  msg_r 
)
static

Make a string from errno_r and msg_r.

Definition at line 127 of file Exception.cc.

void zypp::Exception::log ( const Exception excpt_r,
const CodeLocation where_r,
const char *const  prefix_r 
)
static

Drop a logline on throw, catch or rethrow.

Used by ZYPP_THROW macros macros.

Definition at line 134 of file Exception.cc.

virtual const char* zypp::Exception::what ( ) const
throw (
)
inlineprivatevirtual

Return message string.

Definition at line 267 of file Exception.h.

std::ostream & zypp::Exception::dumpError ( std::ostream &  str) const
private

Called by std::ostream & operator<<.

Prints CodeLocation and the error message provided by dumpOn.

Definition at line 117 of file Exception.cc.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  str,
const Exception obj 
)
friend

Definition at line 120 of file Exception.cc.

std::ostream & operator<< ( std::ostream &  str,
const Exception obj 
)
related

Stream output

Definition at line 120 of file Exception.cc.

Member Data Documentation

CodeLocation zypp::Exception::_where
mutableprivate

Definition at line 262 of file Exception.h.

std::string zypp::Exception::_msg
private

Definition at line 263 of file Exception.h.

History zypp::Exception::_history
private

Definition at line 264 of file Exception.h.


The documentation for this class was generated from the following files: