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__) 181 const CodeLocation & where()
const 185 void relocate(
const CodeLocation & where_r )
const 186 { _where = where_r; }
193 const std::string &
msg()
const 214 void remember(
const Exception & old_r );
219 void addHistory(
const std::string & msg_r );
221 void addHistory( std::string && msg_r );
224 template<
class TContainer>
227 for (
const std::string & el : msgc_r )
231 template<
class TContainer>
234 for ( std::string & el : msgc_r )
235 addHistory( std::move(el) );
240 {
return _history.begin(); }
244 {
return _history.end(); }
248 {
return _history.empty(); }
252 {
return _history.size(); }
264 std::string historyAsString()
const;
267 std::string asUserHistory()
const;
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 );
287 static void log(
const Exception & excpt_r,
const CodeLocation & where_r,
288 const char *
const prefix_r );
296 virtual const char *
what()
const throw()
297 {
return _msg.c_str(); }
303 std::ostream & dumpError( std::ostream & str )
const;
311 namespace exception_detail
314 template<
class TExcpt>
316 template<
class TExcpt>
319 excpt_r.relocate( where_r );
325 template<
class TExcpt>
332 template<
class TExcpt>
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 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.
const std::string & msg() const
Return the message string provided to the ctor.
bool historyEmpty() const
Whether the history list is empty.
String related utilities and Regular expression matching.
void relocate(const CodeLocation &where_r) const
Exchange location on rethrow.
virtual const char * what() const
Return message string.
HistoryIterator historyBegin() const
Iterator pointing to the most recent message.
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
std::list< std::string > History
friend std::ostream & operator<<(std::ostream &str, const CodeLocation &obj)
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
void do_ZYPP_RETHROW(const TExcpt &excpt_r, const CodeLocation &where_r) __attribute__((noreturn))
Helper for ZYPP_THROW macros.
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.
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
Keep FILE, FUNCTION and LINE.
HistorySize historySize() const
The size of the history list.
Easy-to use interface to the ZYPP dependency resolver.
History::const_iterator HistoryIterator
std::string asUserString(const Tp &val_r)
Request a human readable (translated) string representation of Tp [Tp.asUserString()] Classes may imp...