static void assertResKind( const Resolvable::Kind & refers_r )
{
if ( refers_r == Resolvable::Kind() )
- ZYPP_THROW( Exception, "Missing or empty Resolvable::Kind in Capability." );
+ ZYPP_THROW( Exception("Missing or empty Resolvable::Kind in Capability") );
}
/** Check whether \a op_r and \a edition_r make a valid edition spec.
break;
case Rel::NONE_e:
- ZYPP_THROW( Exception, "Operator NONE is not allowed in Capability " );
+ ZYPP_THROW( Exception("Operator NONE is not allowed in Capability") );
break;
case Rel::EQ_e:
break;
}
// SHOULD NOT GET HERE
- ZYPP_THROW( Exception, "Unknow Operator NONE is not allowed in Capability " );
+ ZYPP_THROW( Exception("Unknow Operator NONE is not allowed in Capability") );
return false; // not reached
}
}
else
{
- ZYPP_THROW( Exception, string("Invalid Edition: ")+edition_r );
+ ZYPP_THROW( Exception(string("Invalid Edition: ")+edition_r) );
}
}
char * endptr = NULL;
epoch_t ret = strtoul( epoch_r.c_str(), &endptr, 10 );
if ( *endptr != '\0' )
- ZYPP_THROW( Exception, string("Invalid eopch: ")+epoch_r );
+ ZYPP_THROW( Exception(string("Invalid eopch: ")+epoch_r) );
return ret;
}
{
str::smatch what;
if( ! str::regex_match( vr_r.begin(), vr_r.end(), what, _rxVR ) )
- ZYPP_THROW( Exception, string("Invalid version/release: ")+vr_r );
+ ZYPP_THROW( Exception(string("Invalid version/release: ")+vr_r) );
return vr_r;
}
= _table.find( strval_r );
if ( it == _table.end() )
{
- ZYPP_THROW( Exception, "Rel parse: illegal string value" );
+ ZYPP_THROW( Exception("Rel parse: illegal string value") );
}
return it->second;
}
}
std::ostream & Exception::dumpOn( std::ostream & str ) const
- {
- return str << _msg;
- }
+ { return str << _msg; }
std::ostream & Exception::dumpError( std::ostream & str ) const
- {
- return dumpOn( str << _where << ": " );
- }
+ { return dumpOn( str << _where << ": " ); }
std::ostream & operator<<( std::ostream & str, const Exception & obj )
{ return obj.dumpError( str ); }
+
std::string Exception::strErrno( int errno_r )
- {
- return str::strerror( errno_r );
- }
+ { return str::strerror( errno_r ); }
std::string Exception::strErrno( int errno_r, const std::string & msg_r )
{
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : Exception
- /** Exception stores message and \ref CodeLocation.
+ /** Base class for Exception.
*
- * Use \ref ZYPP_THROW to throw exceptions.
+ * Exception offers to store a message string passed to the ctor.
+ * Derived classes may provide additional information. Overload
+ * \ref dumpOn to provide a proper error text.
+ *
+ * \li Use \ref ZYPP_THROW to throw exceptions.
+ * \li Use \ref ZYPP_CAUGHT If you caught an exceptions in order to handle it.
+ * \li Use \ref ZYPP_RETHROW to rethrow a caught exception.
+ *
+ * The use of these macros is not mandatory. but \c ZYPP_THROW and
+ * \c ZYPP_RETHROW will adjust the code location information stored in
+ * the Exception. All three macros will drop a line in the logfile.
+
* \code
* 43 try
* 44 {
* 45 try
* 46 {
- * 47 ZYPP_THROW_MSG( Exception, "Something bad happened." );
+ * 47 ZYPP_THROW( Exception("Something bad happened.") );
* 48 }
* 49 catch ( Exception & excpt )
* 50 {
void relocate( const CodeLocation & where_r ) const
{ _where = where_r; }
- /** Return the message string provided to the ctor. */
+ /** Return the message string provided to the ctor.
+ * \note This is not neccessarily the complete error message.
+ * The whole error message is provided by \ref asString or
+ * \ref dumpOn.
+ */
const std::string & msg() const
{ return _msg; }
- /** A proper error message. */
+ /** Error message provided by \ref dumpOn as string. */
std::string asString() const;
protected:
- /** Overload this to print a proper error message.
- * CodeLocation is prepended automatically.
- */
+ /** Overload this to print a proper error message. */
virtual std::ostream & dumpOn( std::ostream & str ) const;
public:
virtual const char * what() const throw()
{ return _msg.c_str(); }
- /** Called by <tt>std::ostream & operator\<\<</tt> */
+ /** Called by <tt>std::ostream & operator\<\<</tt>.
+ * Prints \ref CodeLocation and the error message provided by
+ * \ref dumpOn.
+ */
std::ostream & dumpError( std::ostream & str ) const;
};
///////////////////////////////////////////////////////////////////
*/
//@{
/** Drops a logline and throws the Exception. */
-#define ZYPP_DOTHROW(EXCPT)\
+#define ZYPP_THROW(EXCPT)\
_ZYPP_THROW( EXCPT, ZYPP_EX_CODELOCATION )
/** Drops a logline telling the Exception was caught (in order to handle it). */
_ZYPP_RETHROW( EXCPT, ZYPP_EX_CODELOCATION )
- /** Throw Exception built from a message string. */
-#define ZYPP_THROW(EXCPTTYPE, MSG)\
- ZYPP_DOTHROW( EXCPTTYPE( MSG ) )
-
/** Throw Exception built from a message string. */
#define ZYPP_THROW_MSG(EXCPTTYPE, MSG)\
- ZYPP_DOTHROW( EXCPTTYPE( MSG ) )
+ ZYPP_THROW( EXCPTTYPE( MSG ) )
/** Throw Exception built from errno. */
#define ZYPP_THROW_ERRNO(EXCPTTYPE)\
- ZYPP_DOTHROW( EXCPTTYPE( ::zypp::Exception::strErrno(errno) ) )
+ ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(errno) ) )
/** Throw Exception built from errno provided as argument. */
#define ZYPP_THROW_ERRNO1(EXCPTTYPE, ERRNO)\
- ZYPP_DOTHROW( EXCPTTYPE( ::zypp::Exception::strErrno(ERRNO) ) )
+ ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(ERRNO) ) )
/** Throw Exception built from errno and a message string. */
#define ZYPP_THROW_ERRNO_MSG(EXCPTTYPE, MSG)\
- ZYPP_DOTHROW( EXCPTTYPE( ::zypp::Exception::strErrno(errno,MSG) ) )
+ ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(errno,MSG) ) )
/** Throw Exception built from errno provided as argument and a message string */
#define ZYPP_THROW_ERRNO_MSG1(EXCPTTYPE, ERRNO,MSG)\
- ZYPP_DOTHROW( EXCPTTYPE( ::zypp::Exception::strErrno(ERRNO,MSG) ) )
+ ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(ERRNO,MSG) ) )
//@}
/////////////////////////////////////////////////////////////////
MediaAccess::open (const Url& url, const Pathname & preferred_attach_point)
{
if(!url.isValid()) {
- ZYPP_DOTHROW(MediaBadUrlException(url));
+ ZYPP_THROW(MediaBadUrlException(url));
}
close();
{
if ( !_handler ) {
INT << "Error::E_media_not_open" << endl;
- ZYPP_DOTHROW(MediaNotOpenException());
+ ZYPP_THROW(MediaNotOpenException());
}
_handler->attach(next);
}
MediaAccess::disconnect()
{
if ( !_handler )
- ZYPP_DOTHROW(MediaNotOpenException());
+ ZYPP_THROW(MediaNotOpenException());
_handler->disconnect();
}
}
if(checkonly)
- ZYPP_DOTHROW(MediaFileNotFoundException(url(), filename));
+ ZYPP_THROW(MediaFileNotFoundException(url(), filename));
if ( !_handler ) {
INT << "Error::E_media_not_open" << " on provideFile(" << filename << ")" << endl;
- ZYPP_DOTHROW(MediaNotOpenException());
+ ZYPP_THROW(MediaNotOpenException());
}
_handler->provideFile( filename );
{
if ( !_handler ) {
INT << "Error::E_media_not_open" << " on provideDir(" << dirname << ")" << endl;
- ZYPP_DOTHROW(MediaNotOpenException());
+ ZYPP_THROW(MediaNotOpenException());
}
_handler->provideDir( dirname );
{
if ( !_handler ) {
INT << "Error::E_media_not_open" << " on provideDirTree(" << dirname << ")" << endl;
- ZYPP_DOTHROW(MediaNotOpenException());
+ ZYPP_THROW(MediaNotOpenException());
}
_handler->provideDirTree( dirname );
if ( !_handler ) {
INT << "Error::E_media_not_open" << " on dirInfo(" << dirname << ")" << endl;
- ZYPP_DOTHROW(MediaNotOpenException());
+ ZYPP_THROW(MediaNotOpenException());
}
_handler->dirInfo( retlist, dirname, dots );
if ( !_handler ) {
INT << "Error::E_media_not_open" << " on dirInfo(" << dirname << ")" << endl;
- ZYPP_DOTHROW(MediaNotOpenException());
+ ZYPP_THROW(MediaNotOpenException());
}
_handler->dirInfo( retlist, dirname, dots );
, _local_file( "" )
{
if ( _file.empty() ) {
- ZYPP_DOTHROW(MediaBadFilenameException(_file.asString()));
+ ZYPP_THROW(MediaBadFilenameException(_file.asString()));
} else if ( _media ) {
try {
_media->provideFile( _file );
void MediaCurl::attachTo (bool next)
{
if ( next )
- ZYPP_THROW( MediaException, "Error::E_not_supported_by_media");
+ ZYPP_THROW( MediaException("Error::E_not_supported_by_media") );
#warning FIXME implement check for URL validity
#if 0
if ( !_url.isValid() )
- ZYPP_THROW( MediaException, "Error::E_bad_url");
+ ZYPP_THROW( MediaException("Error::E_bad_url") );
#endif
_curl = curl_easy_init();
if ( !_curl ) {
ERR << "curl easy init failed" << endl;
- ZYPP_THROW( MediaException, "Error::E_error");
+ ZYPP_THROW( MediaException("Error::E_error") );
}
_connected = true;
CURLcode ret = curl_easy_setopt( _curl, CURLOPT_ERRORBUFFER, _curlError );
if ( ret != 0 ) {
ERR << "Error setting error buffer" << endl;
- ZYPP_THROW( MediaException, "Error::E_curl_setopt_failed");
+ ZYPP_THROW( MediaException("Error::E_curl_setopt_failed") );
}
ret = curl_easy_setopt( _curl, CURLOPT_FAILONERROR, true );
if ( ret != 0 ) {
ERR << _curlError << endl;
- ZYPP_THROW( MediaException, "Error::E_curl_setopt_failed");
+ ZYPP_THROW( MediaException("Error::E_curl_setopt_failed") );
}
if ( _url.getScheme() == "http" ) {
ret = curl_easy_setopt ( _curl, CURLOPT_FOLLOWLOCATION, true );
if ( ret != 0) {
ERR << _curlError << endl;
- ZYPP_THROW( MediaException, "Error::E_curl_setopt_failed");
+ ZYPP_THROW( MediaException("Error::E_curl_setopt_failed") );
}
ret = curl_easy_setopt ( _curl, CURLOPT_MAXREDIRS, 3L );
if ( ret != 0) {
ERR << _curlError << endl;
- ZYPP_THROW( MediaException, "Error::E_curl_setopt_failed");
+ ZYPP_THROW( MediaException("Error::E_curl_setopt_failed") );
}
}
ret = curl_easy_setopt( _curl, CURLOPT_SSL_VERIFYPEER, 0 );
if ( ret != 0 ) {
ERR << _curlError << endl;
- ZYPP_THROW( MediaException, "Error::E_curl_setopt_failed");
+ ZYPP_THROW( MediaException("Error::E_curl_setopt_failed") );
}
ret = curl_easy_setopt( _curl, CURLOPT_SSL_VERIFYHOST, 0 );
if ( ret != 0 ) {
ERR << _curlError << endl;
- ZYPP_THROW( MediaException, "Error::E_curl_setopt_failed");
+ ZYPP_THROW( MediaException("Error::E_curl_setopt_failed") );
}
}
ret = curl_easy_setopt( _curl, CURLOPT_USERPWD, _userpwd.c_str() );
if ( ret != 0 ) {
ERR << _curlError << endl;
- ZYPP_THROW( MediaException, "Error::E_curl_setopt_failed");
+ ZYPP_THROW( MediaException("Error::E_curl_setopt_failed") );
}
}
ret = curl_easy_setopt( _curl, CURLOPT_PROXY, _proxy.c_str() );
if ( ret != 0 ) {
ERR << _curlError << endl;
- ZYPP_THROW( MediaException, "Error::E_curl_setopt_failed");
+ ZYPP_THROW( MediaException("Error::E_curl_setopt_failed") );
}
/*---------------------------------------------------------------*
ret = curl_easy_setopt( _curl, CURLOPT_PROXYUSERPWD, _proxyuserpwd.c_str() );
if ( ret != 0 ) {
ERR << _curlError << endl;
- ZYPP_THROW( MediaException, "Error::E_curl_setopt_failed");
+ ZYPP_THROW( MediaException("Error::E_curl_setopt_failed") );
}
}
_currentCookieFile.c_str() );
if ( ret != 0 ) {
ERR << _curlError << endl;
- ZYPP_THROW( MediaException, "Error::E_curl_setopt_failed");
+ ZYPP_THROW( MediaException("Error::E_curl_setopt_failed") );
}
ret = curl_easy_setopt( _curl, CURLOPT_COOKIEJAR,
_currentCookieFile.c_str() );
if ( ret != 0 ) {
ERR << _curlError << endl;
- ZYPP_THROW( MediaException, "Error::E_curl_setopt_failed");
+ ZYPP_THROW( MediaException("Error::E_curl_setopt_failed") );
}
ret = curl_easy_setopt( _curl, CURLOPT_PROGRESSFUNCTION,
&MediaCurl::progressCallback );
if ( ret != 0 ) {
ERR << _curlError << endl;
- ZYPP_THROW( MediaException, "Error::E_curl_setopt_failed");
+ ZYPP_THROW( MediaException("Error::E_curl_setopt_failed") );
}
ret = curl_easy_setopt( _curl, CURLOPT_NOPROGRESS, false );
if ( ret != 0 ) {
ERR << _curlError << endl;
- ZYPP_THROW( MediaException, "Error::E_curl_setopt_failed");
+ ZYPP_THROW( MediaException("Error::E_curl_setopt_failed") );
}
}
#warning FIXME implement check for URL validity
#if 0
if(!_url.isValid())
- ZYPP_THROW( MediaException, string("Error::E_bad_url") + " " + _url.toString());
+ ZYPP_THROW( MediaException(string("Error::E_bad_url") + " " + _url.toString()) );
#endif
if(_url.getHost().empty())
- ZYPP_THROW( MediaException, "Error::E_no_host_specified");
+ ZYPP_THROW( MediaException("Error::E_no_host_specified") );
string path = _url.getPathName();
if ( !path.empty() && path != "/" && *path.rbegin() == '/' &&
if( assert_dir( dest.dirname() ) )
{
DBG << "assert_dir " << dest.dirname() << " failed" << endl;
- ZYPP_THROW( MediaException, string("Error::E_system") + string(" ") + dest.dirname().asString());
+ ZYPP_THROW( MediaException(string("Error::E_system") + string(" ") + dest.dirname().asString()) );
}
DBG << "URL: " << url.toString().c_str() << endl;
urlBuffer.c_str() );
if ( ret != 0 ) {
ERR << _curlError << endl;
- ZYPP_THROW( MediaException, "Error::E_curl_setopt_failed");
+ ZYPP_THROW( MediaException("Error::E_curl_setopt_failed") );
}
FILE *file = fopen( destNew.c_str(), "w" );
if ( !file ) {
ERR << "fopen failed for file '" << destNew << "'" << endl;
- ZYPP_THROW( MediaException, string("Error::E_write_error") + string(" ") + destNew);
+ ZYPP_THROW( MediaException(string("Error::E_write_error") + string(" ") + destNew) );
}
ret = curl_easy_setopt( _curl, CURLOPT_WRITEDATA, file );
if ( ret != 0 ) {
fclose( file );
ERR << _curlError << endl;
- ZYPP_THROW( MediaException, "Error::E_curl_setopt_failed");
+ ZYPP_THROW( MediaException("Error::E_curl_setopt_failed") );
}
// Set callback and perform.
#if 0
report->stop( err );
#endif
- ZYPP_THROW( MediaException, err + string(" ") + _curlError);
+ ZYPP_THROW( MediaException(err + string(" ") + _curlError) );
}
}
break;
#if 0
report->stop( err );
#endif
- ZYPP_THROW( MediaException, err + string(" ") + _curlError);
+ ZYPP_THROW( MediaException(err + string(" ") + _curlError) );
}
if ( rename( destNew, dest ) != 0 ) {
#if 0
report->stop( Error::E_write_error );
#endif
- ZYPP_THROW( MediaException, "Error::E_write_error");
+ ZYPP_THROW( MediaException("Error::E_write_error") );
}
#warning FIXME reenable change report
}
catch (const MediaException & excpt_r)
{
- ZYPP_THROW( MediaException, "Error::E_not_supported_by_media");
+ ZYPP_THROW( MediaException("Error::E_not_supported_by_media") );
}
}
}
catch (const MediaException & excpt_r)
{
- ZYPP_THROW( MediaException, "Error::E_not_supported_by_media");
+ ZYPP_THROW( MediaException("Error::E_not_supported_by_media") );
}
}
{
public:
/** Ctor taking message.
- * Use \ref ZYPP_DOTHROW to throw exceptions.
+ * Use \ref ZYPP_THROW to throw exceptions.
*/
MediaMountException( const std::string & error_r,
const std::string & source_r,
{
public:
/** Ctor taking message.
- * Use \ref ZYPP_DOTHROW to throw exceptions.
+ * Use \ref ZYPP_THROW to throw exceptions.
*/
MediaUnmountException( const std::string & error_r,
const std::string & path_r )
std::string _url;
};
-
+
/////////////////////////////////////////////////////////////////
} // namespace media
if ( _attachPoint.empty() ) {
ERR << "Error::E_bad_attachpoint" << endl;
- ZYPP_THROW( MediaException, "Error::E_bad_attachpoint");
+ ZYPP_THROW( MediaException("Error::E_bad_attachpoint") );
}
try {
if ( !_isAttached ) {
INT << "Error::E_not_attached" << " on provideFileCopy(" << srcFilename
<< "," << targetFilename << ")" << endl;
- ZYPP_DOTHROW(MediaNotAttachedException(url()));
+ ZYPP_THROW(MediaNotAttachedException(url()));
}
try {
{
if ( !_isAttached ) {
INT << "Error: Not attached on provideFile(" << filename << ")" << endl;
- ZYPP_DOTHROW(MediaNotAttachedException(url()));
+ ZYPP_THROW(MediaNotAttachedException(url()));
}
try {
{
if ( !_isAttached ) {
INT << "Error: Not attached on provideDir(" << dirname << ")" << endl;
- ZYPP_DOTHROW(MediaNotAttachedException(url()));
+ ZYPP_THROW(MediaNotAttachedException(url()));
}
try {
getDir( dirname, /*recursive*/false ); // pass to concrete handler
{
if ( !_isAttached ) {
INT << "Error Not attached on provideDirTree(" << dirname << ")" << endl;
- ZYPP_DOTHROW(MediaNotAttachedException(url()));
+ ZYPP_THROW(MediaNotAttachedException(url()));
}
try {
if ( !_isAttached ) {
INT << "Error: Not attached on dirInfo(" << dirname << ")" << endl;
- ZYPP_DOTHROW(MediaNotAttachedException(url()));
+ ZYPP_THROW(MediaNotAttachedException(url()));
}
try {
if ( !_isAttached ) {
INT << "Error: Not attached on dirInfo(" << dirname << ")" << endl;
- ZYPP_DOTHROW(MediaNotAttachedException(url()));
+ ZYPP_THROW(MediaNotAttachedException(url()));
}
try {
ifstream dir( localPath( dirFile ).asString().c_str() );
if ( dir.fail() ) {
ERR << "Unable to load '" << localPath( dirFile ) << "'" << endl;
- ZYPP_DOTHROW(MediaSystemException(url(),
+ ZYPP_THROW(MediaSystemException(url(),
"Unable to load '" + localPath( dirFile ).asString() + "'"));
}
}
if (info.isExist())
- ZYPP_DOTHROW(MediaNotAFileException(url(), localPath(filename)));
+ ZYPP_THROW(MediaNotAFileException(url(), localPath(filename)));
else
- ZYPP_DOTHROW(MediaFileNotFoundException(url(), filename));
+ ZYPP_THROW(MediaFileNotFoundException(url(), filename));
}
}
if ( copy( localPath( srcFilename ), targetFilename ) != 0 ) {
- ZYPP_DOTHROW(MediaWriteException(targetFilename));
+ ZYPP_THROW(MediaWriteException(targetFilename));
}
}
}
if (info.isExist())
- ZYPP_DOTHROW(MediaNotADirException(url(), localPath(dirname)));
+ ZYPP_THROW(MediaNotADirException(url(), localPath(dirname)));
else
- ZYPP_DOTHROW(MediaFileNotFoundException(url(), dirname));
+ ZYPP_THROW(MediaFileNotFoundException(url(), dirname));
}
///////////////////////////////////////////////////////////////////
{
PathInfo info( localPath( dirname ) );
if( ! info.isDir() ) {
- ZYPP_DOTHROW(MediaNotADirException(url(), localPath(dirname)));
+ ZYPP_THROW(MediaNotADirException(url(), localPath(dirname)));
}
#if NONREMOTE_DIRECTORY_YAST
// readdir
int res = readdir( retlist, info.path(), dots );
if ( res )
- ZYPP_DOTHROW(MediaSystemException(url(), "readdir failed"));
+ ZYPP_THROW(MediaSystemException(url(), "readdir failed"));
#if NONREMOTE_DIRECTORY_YAST
}
{
PathInfo info( localPath( dirname ) );
if( ! info.isDir() ) {
- ZYPP_DOTHROW(MediaNotADirException(url(), localPath(dirname)));
+ ZYPP_THROW(MediaNotADirException(url(), localPath(dirname)));
}
#if NONREMOTE_DIRECTORY_YAST
// readdir
int res = readdir( retlist, info.path(), dots );
if ( res )
- ZYPP_DOTHROW(MediaSystemException(url(), "readdir failed"));
+ ZYPP_THROW(MediaSystemException(url(), "readdir failed"));
#if NONREMOTE_DIRECTORY_YAST
}
#endif
if ( process == NULL )
{
- ZYPP_DOTHROW(MediaMountException(source, target, "Error::E_mount_failed"));
+ ZYPP_THROW(MediaMountException(source, target, "Error::E_mount_failed"));
}
string value;
if ( err != "" ) {
WAR << "mount " << source << " " << target << ": " << err << endl;
- ZYPP_DOTHROW(MediaMountException(source, target, err));
+ ZYPP_THROW(MediaMountException(source, target, err));
} else {
MIL << "mounted " << source << " " << target << endl;
}
if ( process == NULL )
{
- ZYPP_DOTHROW(MediaUnmountException("E_mount_failed", path));
+ ZYPP_THROW(MediaUnmountException("E_mount_failed", path));
}
string value;
if ( err != "") {
WAR << "umount " << path << ": " << err << endl;
- ZYPP_DOTHROW(MediaUnmountException(err, path));
+ ZYPP_THROW(MediaUnmountException(err, path));
} else {
MIL << "unmounted " << path << endl;
}
catch (...)
{
ERR << "Cannot read repomd file, cannot initialize source" << endl;
-// ZYPP_THROW( Exception, "Cannot read repomd file, cannot initialize source" );
+// ZYPP_THROW( Exception("Cannot read repomd file, cannot initialize source") );
}
try {
// now put other and filelist data to structures for easier find