12 #ifndef ZYPP_BASE_EXCEPTION_H
13 #define ZYPP_BASE_EXCEPTION_H
25 namespace exception_detail
43 const std::string & func_r,
60 #define ZYPP_EX_CODELOCATION ::zypp::exception_detail::CodeLocation(( *__FILE__ == '/' ? strrchr( __FILE__, '/' ) + 1 : __FILE__ ),__FUNCTION__,__LINE__)
63 std::ostream &
operator<<( std::ostream & str,
const CodeLocation & obj );
185 const std::string &
msg()
const
246 virtual std::ostream &
dumpOn( std::ostream & str )
const;
250 static std::string
strErrno(
int errno_r );
252 static std::string
strErrno(
int errno_r,
const std::string & msg_r );
259 const char *
const prefix_r );
267 virtual const char *
what()
const throw()
268 {
return _msg.c_str(); }
274 std::ostream &
dumpError( std::ostream & str )
const;
279 std::ostream &
operator<<( std::ostream & str,
const Exception & obj );
284 template<
class _Excpt>
285 void _ZYPP_THROW(
const _Excpt & excpt_r,
const exception_detail::CodeLocation & where_r ) __attribute__((noreturn));
286 template<
class _Excpt>
289 excpt_r.relocate( where_r );
295 template<
class _Excpt>
302 template<
class _Excpt>
303 void _ZYPP_RETHROW(
const _Excpt & excpt_r,
const exception_detail::CodeLocation & where_r ) __attribute__((noreturn));
304 template<
class _Excpt>
308 excpt_r.relocate( where_r );
320 #define ZYPP_THROW(EXCPT)\
321 _ZYPP_THROW( EXCPT, ZYPP_EX_CODELOCATION )
324 #define ZYPP_CAUGHT(EXCPT)\
325 _ZYPP_CAUGHT( EXCPT, ZYPP_EX_CODELOCATION )
328 #define ZYPP_RETHROW(EXCPT)\
329 _ZYPP_RETHROW( EXCPT, ZYPP_EX_CODELOCATION )
333 #define ZYPP_THROW_MSG(EXCPTTYPE, MSG)\
334 ZYPP_THROW( EXCPTTYPE( MSG ) )
337 #define ZYPP_THROW_ERRNO(EXCPTTYPE)\
338 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(errno) ) )
341 #define ZYPP_THROW_ERRNO1(EXCPTTYPE, ERRNO)\
342 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(ERRNO) ) )
345 #define ZYPP_THROW_ERRNO_MSG(EXCPTTYPE, MSG)\
346 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(errno,MSG) ) )
349 #define ZYPP_THROW_ERRNO_MSG1(EXCPTTYPE, ERRNO,MSG)\
350 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(ERRNO,MSG) ) )
356 #endif // ZYPP_BASE_EXCEPTION_H
std::string historyAsString() const
The history as string.
const std::string & msg() const
Return the message string provided to the ctor.
std::ostream & operator<<(std::ostream &str, const CodeLocation &obj)
void _ZYPP_THROW(const _Excpt &excpt_r, const exception_detail::CodeLocation &where_r) __attribute__((noreturn))
Helper for ZYPP_THROW macros.
bool historyEmpty() const
Whether the history list is empty.
static std::string strErrno(int errno_r)
Make a string from errno_r.
const CodeLocation & where() const
Return CodeLocation.
void addHistory(const std::string &msg_r)
Add some message text to the history.
virtual std::ostream & dumpOn(std::ostream &str) const
Overload this to print a proper error message.
void relocate(const CodeLocation &where_r) const
Exchange location on rethrow.
virtual const char * what() const
Return message string.
void _ZYPP_CAUGHT(const _Excpt &excpt_r, const exception_detail::CodeLocation &where_r)
Helper for ZYPP_THROW macros.
HistoryIterator historyBegin() const
Iterator pointing to the most recent message.
void remember(const Exception &old_r)
Store an other Exception as history.
static void log(const Exception &excpt_r, const CodeLocation &where_r, const char *const prefix_r)
Drop a logline on throw, catch or rethrow.
void _ZYPP_RETHROW(const _Excpt &excpt_r, const exception_detail::CodeLocation &where_r) __attribute__((noreturn))
Helper for ZYPP_THROW macros.
std::ostream & operator<<(std::ostream &str, const Exception &obj)
std::list< std::string > History
friend std::ostream & operator<<(std::ostream &str, const CodeLocation &obj)
std::ostream & dumpError(std::ostream &str) const
Called by std::ostream & operator<<.
std::string asString() const
Error message provided by dumpOn as string.
virtual ~Exception()
Dtor.
std::string asString() const
Location as string.
CodeLocation(const std::string &file_r, const std::string &func_r, unsigned line_r)
Ctor.
HistoryIterator historyEnd() const
Iterator pointing behind the last message.
friend std::ostream & operator<<(std::ostream &str, const Exception &obj)
Base class for Exception.
History::size_type HistorySize
exception_detail::CodeLocation CodeLocation
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
Keep FILE, FUNCTION and LINE.
HistorySize historySize() const
The size of the history list.
History::const_iterator HistoryIterator
std::string asUserString() const
Translated error message as string suitable for the user.