zypp::Exception Class Reference

Base class for Exception. More...

#include <Exception.h>

Inheritance diagram for zypp::Exception:

exception zypp::FailedSourcesRestoreException zypp::media::MediaException zypp::parser::tagfile::ParseException zypp::source::SkipRequestedException zypp::SourcesAlreadyRestoredException zypp::target::hal::HalException zypp::target::rpm::RpmException zypp::target::TargetException zypp::thread::MutexException zypp::url::UrlException zypp::ZYppFactoryException List of all members.

Public Types

typedef exception_detail::CodeLocation CodeLocation

Public Member Functions

 Exception ()
 Default ctor.
 Exception (const std::string &msg_r)
 Ctor taking a message.
virtual ~Exception () throw ()
 Dtor.
const CodeLocationwhere () 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.

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

Friends

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.

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.
Todo:
maybe location and message stack.

Definition at line 114 of file Exception.h.


Member Typedef Documentation

typedef exception_detail::CodeLocation zypp::Exception::CodeLocation
 

Definition at line 119 of file Exception.h.


Constructor & Destructor Documentation

zypp::Exception::Exception  ) 
 

Default ctor.

Use ZYPP_THROW macros to throw exceptions.

Definition at line 44 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 47 of file Exception.cc.

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

Dtor.

Definition at line 51 of file Exception.cc.


Member Function Documentation

const CodeLocation& zypp::Exception::where  )  const [inline]
 

Return CodeLocation.

Definition at line 135 of file Exception.h.

References _where.

void zypp::Exception::relocate const CodeLocation where_r  )  const [inline]
 

Exchange location on rethrow.

Definition at line 139 of file Exception.h.

References _where.

const std::string& zypp::Exception::msg  )  const [inline]
 

Return the message string provided to the ctor.

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

Definition at line 147 of file Exception.h.

References _msg.

Referenced by zypp::target::hal::HalException::dumpOn(), and zypp::media::MediaCurl::getFileCopy().

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

Error message provided by dumpOn as string.

Definition at line 54 of file Exception.cc.

References dumpOn(), and zypp::solver::detail::str.

Referenced by zypp::FailedSourcesRestoreException::append().

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

Translated error message as string suitable for the user.

Definition at line 61 of file Exception.cc.

References _, dumpOn(), and zypp::solver::detail::str.

Referenced by zypp::FailedSourcesRestoreException::append(), zypp::target::rpm::convertV3toV4(), zypp::FailedSourcesRestoreException::dumpOnTranslated(), zypp::target::rpm::RpmDb::getPackages(), zypp::target::RpmRemovePackageReceiver::problem(), zypp::target::RpmInstallPackageReceiver::problem(), and zypp::target::rpm::RpmDb::rebuildDatabase().

std::ostream & zypp::Exception::dumpOn std::ostream &  str  )  const [protected, virtual]
 

Overload this to print a proper error message.

Reimplemented in 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::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::MediaNotDesiredException, zypp::media::MediaIsSharedException, zypp::media::MediaNotEjectedException, zypp::parser::tagfile::ParseException, zypp::FailedSourcesRestoreException, 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 71 of file Exception.cc.

References _msg.

Referenced by asString(), asUserString(), dumpError(), and zypp::parser::tagfile::ParseException::dumpOn().

std::string zypp::Exception::strErrno int  errno_r  )  [static]
 

Make a string from errno_r.

Definition at line 81 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 84 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 91 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]
 

Return message string.

Definition at line 179 of file Exception.h.

References _msg.

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 74 of file Exception.cc.

References _where, and dumpOn().

Referenced by zypp::operator<<().


Friends And Related Function Documentation

std::ostream & operator<< std::ostream &  str,
const Exception obj
[friend]
 

Stream output

Definition at line 77 of file Exception.cc.


Member Data Documentation

CodeLocation zypp::Exception::_where [mutable, private]
 

Definition at line 175 of file Exception.h.

Referenced by dumpError(), relocate(), and where().

std::string zypp::Exception::_msg [private]
 

Reimplemented in zypp::media::MediaBadUrlException, zypp::media::MediaCurlException, and zypp::media::MediaCurlSetOptException.

Definition at line 176 of file Exception.h.

Referenced by dumpOn(), msg(), and what().


The documentation for this class was generated from the following files:
Generated on Thu Jul 6 00:07:30 2006 for zypp by  doxygen 1.4.6