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 );
193 const std::string &
msg()
const 224 template<
class TContainer>
227 for (
const std::string & el : msgc_r )
231 template<
class TContainer>
234 for ( std::string & el : msgc_r )
273 virtual std::ostream &
dumpOn( std::ostream &
str )
const;
277 static std::string
strErrno(
int errno_r );
279 static std::string
strErrno(
int errno_r,
const std::string & msg_r );
281 static std::string
strErrno(
int errno_r, std::string && msg_r );
288 const char *
const prefix_r );
296 virtual const char *
what()
const throw()
297 {
return _msg.c_str(); }
308 std::ostream &
operator<<( std::ostream &
str,
const Exception & obj );
311 namespace exception_detail
314 template<
class TExcpt>
315 void do_ZYPP_THROW(
const TExcpt & excpt_r,
const CodeLocation & where_r ) __attribute__((noreturn));
316 template<
class TExcpt>
319 excpt_r.relocate( where_r );
325 template<
class TExcpt>
332 template<
class TExcpt>
333 void do_ZYPP_RETHROW(
const TExcpt & excpt_r,
const CodeLocation & where_r ) __attribute__((noreturn));
334 template<
class TExcpt>
338 excpt_r.relocate( where_r );
350 #define ZYPP_THROW(EXCPT)\ 351 ::zypp::exception_detail::do_ZYPP_THROW( EXCPT, ZYPP_EX_CODELOCATION ) 354 #define ZYPP_CAUGHT(EXCPT)\ 355 ::zypp::exception_detail::do_ZYPP_CAUGHT( EXCPT, ZYPP_EX_CODELOCATION ) 358 #define ZYPP_RETHROW(EXCPT)\ 359 ::zypp::exception_detail::do_ZYPP_RETHROW( EXCPT, ZYPP_EX_CODELOCATION ) 363 #define ZYPP_THROW_MSG(EXCPTTYPE, MSG)\ 364 ZYPP_THROW( EXCPTTYPE( MSG ) ) 367 #define ZYPP_THROW_ERRNO(EXCPTTYPE)\ 368 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(errno) ) ) 371 #define ZYPP_THROW_ERRNO1(EXCPTTYPE, ERRNO)\ 372 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(ERRNO) ) ) 375 #define ZYPP_THROW_ERRNO_MSG(EXCPTTYPE, MSG)\ 376 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(errno,MSG) ) ) 379 #define ZYPP_THROW_ERRNO_MSG1(EXCPTTYPE, ERRNO,MSG)\ 380 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(ERRNO,MSG) ) ) 386 #endif // ZYPP_BASE_EXCEPTION_H HistoryIterator historyEnd() const
Iterator pointing behind the last message.
void addToHistory(const TContainer &msgc_r)
addHistory from string container types (oldest first)
void do_ZYPP_CAUGHT(const TExcpt &excpt_r, const CodeLocation &where_r)
Helper for ZYPP_THROW macros.
std::ostream & operator<<(std::ostream &str, const CodeLocation &obj)
virtual std::ostream & dumpOn(std::ostream &str) const
Overload this to print a proper error message.
static std::string strErrno(int errno_r)
Make a string from errno_r.
void addHistory(const std::string &msg_r)
Add some message text to the history.
String related utilities and Regular expression matching.
virtual const char * what() const
Return message string.
HistorySize historySize() const
The size of the history list.
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 moveToHistory(TContainer &&msgc_r)
addHistory from string container types (oldest first) moving
HistoryIterator historyBegin() const
Iterator pointing to the most recent message.
std::ostream & operator<<(std::ostream &str, const Exception &obj)
std::list< std::string > History
std::string asString() const
Error message provided by dumpOn as string.
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
std::string asUserString() const
Translated error message as string suitable for the user.
friend std::ostream & operator<<(std::ostream &str, const CodeLocation &obj)
const CodeLocation & where() const
Return CodeLocation.
bool historyEmpty() const
Whether the history list is empty.
std::string historyAsString() const
The history as string.
virtual ~Exception()
Dtor.
void do_ZYPP_RETHROW(const TExcpt &excpt_r, const CodeLocation &where_r) __attribute__((noreturn))
Helper for ZYPP_THROW macros.
CodeLocation(const std::string &file_r, const std::string &func_r, unsigned line_r)
Ctor.
friend std::ostream & operator<<(std::ostream &str, const Exception &obj)
Base class for Exception.
void do_ZYPP_THROW(const TExcpt &excpt_r, const CodeLocation &where_r) __attribute__((noreturn))
Helper for ZYPP_THROW macros.
History::size_type HistorySize
exception_detail::CodeLocation CodeLocation
std::ostream & dumpError(std::ostream &str) const
Called by std::ostream & operator<<.
Keep FILE, FUNCTION and LINE.
void relocate(const CodeLocation &where_r) const
Exchange location on rethrow.
Easy-to use interface to the ZYPP dependency resolver.
History::const_iterator HistoryIterator
std::string asString() const
Location as string.
const std::string & msg() const
Return the message string provided to the ctor.