#include <Exception.h>
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. | |
Exception (const std::string &msg_r) | |
Ctor taking a message. | |
virtual | ~Exception () throw () |
Dtor. | |
const CodeLocation & | where () const |
Return CodeLocation. | |
void | relocate (const CodeLocation &where_r) const |
Exchange location on rethrow. | |
const std::string & | msg () const |
Return the message string provided to the ctor. | |
std::string | asString () const |
Error message provided by dumpOn as string. | |
std::string | asUserString () const |
Translated error message as string suitable for the user. | |
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. | |
void | addHistory (const std::string &msg_r) |
Add some message text to the history. | |
HistoryIterator | historyBegin () const |
Iterator pointing to the most recent message. | |
HistoryIterator | historyEnd () const |
Iterator pointing behind the last message. | |
bool | historyEmpty () const |
Whether the history list is empty. | |
HistorySize | historySize () const |
The size of the history list. | |
std::string | historyAsString () const |
The history as string. | |
std::string | asUserHistory () const |
A single (multiline) string composed of asUserString and historyAsString. | |
Static Public Member Functions | |
static std::string | strErrno (int errno_r) |
Make a string from errno_r. | |
static std::string | strErrno (int errno_r, const std::string &msg_r) |
Make a string from errno_r and msg_r. | |
static void | log (const Exception &excpt_r, const CodeLocation &where_r, const char *const prefix_r) |
Drop a logline on throw, catch or rethrow. | |
Protected Member Functions | |
virtual std::ostream & | dumpOn (std::ostream &str) const |
Overload this to print a proper error message. | |
Private Member Functions | |
virtual const char * | what () const throw () |
Return message string. | |
std::ostream & | dumpError (std::ostream &str) const |
Called by std::ostream & operator<< . | |
Private Attributes | |
CodeLocation | _where |
std::string | _msg |
History | _history |
Friends | |
std::ostream & | operator<< (std::ostream &str, const Exception &obj) |
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.
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 }
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:
Definition at line 143 of file Exception.h.
Definition at line 148 of file Exception.h.
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.
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 | ( | ) | throw () [virtual] |
const CodeLocation& zypp::Exception::where | ( | ) | const [inline] |
void zypp::Exception::relocate | ( | const CodeLocation & | where_r | ) | const [inline] |
const std::string& zypp::Exception::msg | ( | ) | const [inline] |
Return the message string provided to the ctor.
Definition at line 179 of file Exception.h.
References _msg.
Referenced by zypp::target::hal::HalException::dumpOn(), zypp::media::MediaUnauthorizedException::dumpOn(), zypp::UserRequestException::dumpOn(), zypp::media::fillSettingsFromUrl(), and zypp::Fetcher::Impl::provideToDest().
std::string zypp::Exception::asString | ( | ) | const |
Error message provided by dumpOn as string.
Definition at line 55 of file Exception.cc.
References dumpOn().
Referenced by zypp::misc::defaultLoadSystem().
std::string zypp::Exception::asUserString | ( | ) | const |
Translated error message as string suitable for the user.
Definition at line 62 of file Exception.cc.
Referenced by asUserHistory(), zypp::target::rpm::convertV3toV4(), zypp::MediaSetAccess::provide(), and remember().
void zypp::Exception::remember | ( | const Exception & | old_r | ) |
Store an other Exception as history.
Definition at line 85 of file Exception.cc.
References _history, and asUserString().
Referenced by zypp::target::TargetImpl::buildCache(), zypp::RepoManager::buildCache(), zypp::CheckAccessDeleted::check(), zypp::media::MediaHandler::getDirInfo(), zypp::media::MediaISO::MediaISO(), zypp::parser::HistoryLogReader::Impl::parseLine(), zypp::RepoManager::probe(), zypp::RepoManager::probeService(), zypp::MediaSetAccess::provide(), zypp::repo::RepoMediaAccess::provideFile(), zypp::Fetcher::Impl::provideToDest(), and zypp::RepoManager::refreshMetadata().
void zypp::Exception::addHistory | ( | const std::string & | msg_r | ) |
Add some message text to the history.
Definition at line 95 of file Exception.cc.
References _history.
Referenced by zypp::media::MediaAria2c::getFileCopy(), zypp::parser::HistoryLogReader::Impl::parseLine(), zypp::PluginFrameException::PluginFrameException(), and zypp::PluginScriptException::PluginScriptException().
HistoryIterator zypp::Exception::historyBegin | ( | ) | const [inline] |
Iterator pointing to the most recent message.
Definition at line 206 of file Exception.h.
References _history.
Referenced by historyAsString().
HistoryIterator zypp::Exception::historyEnd | ( | ) | const [inline] |
Iterator pointing behind the last message.
Definition at line 210 of file Exception.h.
References _history.
Referenced by historyAsString().
bool zypp::Exception::historyEmpty | ( | ) | const [inline] |
Whether the history list is empty.
Definition at line 214 of file Exception.h.
References _history.
Referenced by asUserHistory().
HistorySize zypp::Exception::historySize | ( | ) | const [inline] |
std::string zypp::Exception::historyAsString | ( | ) | const |
The history as string.
Empty if historyEmpty. Otherwise:
History: - most recent message - 2nd message ... - oldest message
Definition at line 100 of file Exception.cc.
References _, zypp::dumpRange(), historyBegin(), and historyEnd().
Referenced by asUserHistory(), and zypp::misc::defaultLoadSystem().
std::string zypp::Exception::asUserHistory | ( | ) | const |
A single (multiline) string composed of asUserString and historyAsString.
Definition at line 71 of file Exception.cc.
References asUserString(), historyAsString(), and historyEmpty().
Referenced by zypp::target::TargetImpl::buildCache(), zypp::media::MediaCurl::getFileCopy(), zypp::media::MediaAria2c::getFileCopy(), zypp::target::RpmRemovePackageReceiver::problem(), zypp::target::RpmInstallPackageReceiver::problem(), zypp::repo::PackageProvider::providePackage(), zypp::target::rpm::RpmDb::rebuildDatabase(), and zypp::repo::PackageProvider::tryDelta().
std::ostream & zypp::Exception::dumpOn | ( | std::ostream & | str | ) | const [protected, virtual] |
Overload this to print a proper error message.
Reimplemented in zypp::UserRequestException, zypp::media::MediaMountException, zypp::media::MediaUnmountException, zypp::media::MediaBadFilenameException, zypp::media::MediaNotOpenException, zypp::media::MediaFileNotFoundException, zypp::media::MediaWriteException, zypp::media::MediaNotAttachedException, zypp::media::MediaBadAttachPointException, zypp::media::MediaCurlInitException, zypp::media::MediaMetalinkInitException, zypp::media::MediaAria2cInitException, zypp::media::MediaSystemException, zypp::media::MediaNotAFileException, zypp::media::MediaNotADirException, zypp::media::MediaBadUrlException, zypp::media::MediaBadUrlEmptyHostException, zypp::media::MediaBadUrlEmptyFilesystemException, zypp::media::MediaBadUrlEmptyDestinationException, zypp::media::MediaUnsupportedUrlSchemeException, zypp::media::MediaNotSupportedException, zypp::media::MediaCurlException, zypp::media::MediaCurlSetOptException, zypp::media::MediaMetalinkException, zypp::media::MediaMetalinkSetOptException, zypp::media::MediaAria2cException, zypp::media::MediaAria2cSetOptException, zypp::media::MediaNotDesiredException, zypp::media::MediaIsSharedException, zypp::media::MediaNotEjectedException, zypp::media::MediaUnauthorizedException, zypp::media::MediaForbiddenException, zypp::media::MediaTimeoutException, zypp::media::MediaTemporaryProblemException, zypp::media::MediaBadCAException, zypp::media::MediaNoLoopDeviceException, zypp::parser::ParseException, zypp::repo::RepoException, zypp::repo::ServiceException, zypp::target::hal::HalException, zypp::target::rpm::RpmInvalidRootException, zypp::target::rpm::RpmAccessBlockedException, zypp::target::rpm::RpmSubprocessException, zypp::target::rpm::RpmInitException, zypp::target::rpm::RpmDbOpenException, zypp::target::rpm::RpmDbAlreadyOpenException, zypp::target::rpm::RpmDbNotOpenException, zypp::target::rpm::RpmDbConvertException, zypp::target::rpm::RpmNullDatabaseException, and zypp::target::TargetAbortedException.
Definition at line 110 of file Exception.cc.
References _msg.
Referenced by asString(), asUserString(), and dumpError().
std::string zypp::Exception::strErrno | ( | int | errno_r | ) | [static] |
Make a string from errno_r.
Definition at line 120 of file Exception.cc.
References zypp::str::strerror().
Referenced by strErrno().
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 123 of file Exception.cc.
References strErrno().
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 130 of file Exception.cc.
References INT.
Referenced by zypp::_ZYPP_CAUGHT(), zypp::_ZYPP_RETHROW(), and zypp::_ZYPP_THROW().
virtual const char* zypp::Exception::what | ( | ) | const throw () [inline, private, virtual] |
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 113 of file Exception.cc.
References _where, and dumpOn().
Referenced by zypp::operator<<().
std::ostream & operator<< | ( | std::ostream & | str, | |
const Exception & | obj | |||
) | [friend] |
Stream output
Definition at line 116 of file Exception.cc.
CodeLocation zypp::Exception::_where [mutable, private] |
std::string zypp::Exception::_msg [private] |
Reimplemented in zypp::media::MediaBadUrlException, zypp::media::MediaCurlException, zypp::media::MediaCurlSetOptException, zypp::media::MediaMetalinkException, zypp::media::MediaMetalinkSetOptException, zypp::media::MediaAria2cException, zypp::media::MediaAria2cSetOptException, zypp::media::MediaForbiddenException, zypp::media::MediaTimeoutException, zypp::media::MediaTemporaryProblemException, zypp::media::MediaBadCAException, and zypp::media::MediaNoLoopDeviceException.
Definition at line 257 of file Exception.h.
History zypp::Exception::_history [private] |
Definition at line 258 of file Exception.h.
Referenced by addHistory(), historyBegin(), historyEmpty(), historyEnd(), historySize(), and remember().