Go to the documentation of this file.
12 #ifndef ZYPP_BASE_EXCEPTION_H
13 #define ZYPP_BASE_EXCEPTION_H
20 #include <type_traits>
27 namespace exception_detail
45 const std::string & func_r,
62 #define ZYPP_EX_CODELOCATION ::zypp::exception_detail::CodeLocation(( *__FILE__ == '/' ? strrchr( __FILE__, '/' ) + 1 : __FILE__ ),__FUNCTION__,__LINE__)
65 std::ostream &
operator<<( std::ostream &
str,
const CodeLocation & obj );
195 const std::string &
msg()
const
226 template<
class TContainer>
229 for (
const std::string & el : msgc_r )
233 template<
class TContainer>
236 for ( std::string & el : msgc_r )
275 virtual std::ostream &
dumpOn( std::ostream &
str )
const;
279 static std::string
strErrno(
int errno_r );
281 static std::string
strErrno(
int errno_r,
const std::string & msg_r );
283 static std::string
strErrno(
int errno_r, std::string && msg_r );
290 const char *
const prefix_r );
292 static void log(
const char * typename_r,
const CodeLocation & where_r,
293 const char *
const prefix_r );
300 virtual const char *
what()
const throw()
301 {
return _msg.c_str(); }
312 std::ostream &
operator<<( std::ostream &
str,
const Exception & obj );
315 namespace exception_detail
318 template<
class TExcpt>
319 using EnableIfIsException =
typename std::enable_if< std::is_base_of<Exception,TExcpt>::value,
int>::type;
322 template<
class TExcpt>
327 template<
class TExcpt, EnableIfIsException<TExcpt> = 0>
329 template<
class TExcpt, EnableIfIsException<TExcpt>>
332 excpt_r.relocate( where_r );
338 template<
class TExcpt, EnableIfNotException<TExcpt> = 0>
339 void do_ZYPP_THROW(
const TExcpt & excpt_r,
const CodeLocation & where_r ) __attribute__((noreturn));
340 template<
class TExcpt, EnableIfNotException<TExcpt>>
341 void do_ZYPP_THROW(
const TExcpt & excpt_r,
const CodeLocation & where_r )
349 template<
class TExcpt, EnableIfIsException<TExcpt> = 0>
356 template<
class TExcpt, EnableIfNotException<TExcpt> = 0>
357 void do_ZYPP_CAUGHT(
const TExcpt & excpt_r,
const CodeLocation & where_r )
364 template<
class TExcpt, EnableIfIsException<TExcpt> = 0>
365 void do_ZYPP_RETHROW(
const TExcpt & excpt_r,
const CodeLocation & where_r ) __attribute__((noreturn));
366 template<
class TExcpt, EnableIfIsException<TExcpt>>
370 excpt_r.relocate( where_r );
375 template<
class TExcpt, EnableIfNotException<TExcpt> = 0>
376 void do_ZYPP_RETHROW(
const TExcpt & excpt_r,
const CodeLocation & where_r ) __attribute__((noreturn));
377 template<
class TExcpt, EnableIfNotException<TExcpt>>
378 void do_ZYPP_RETHROW(
const TExcpt & excpt_r,
const CodeLocation & where_r )
392 #define ZYPP_THROW(EXCPT)\
393 ::zypp::exception_detail::do_ZYPP_THROW( EXCPT, ZYPP_EX_CODELOCATION )
396 #define ZYPP_CAUGHT(EXCPT)\
397 ::zypp::exception_detail::do_ZYPP_CAUGHT( EXCPT, ZYPP_EX_CODELOCATION )
400 #define ZYPP_RETHROW(EXCPT)\
401 ::zypp::exception_detail::do_ZYPP_RETHROW( EXCPT, ZYPP_EX_CODELOCATION )
405 #define ZYPP_THROW_MSG(EXCPTTYPE, MSG)\
406 ZYPP_THROW( EXCPTTYPE( MSG ) )
409 #define ZYPP_THROW_ERRNO(EXCPTTYPE)\
410 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(errno) ) )
413 #define ZYPP_THROW_ERRNO1(EXCPTTYPE, ERRNO)\
414 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(ERRNO) ) )
417 #define ZYPP_THROW_ERRNO_MSG(EXCPTTYPE, MSG)\
418 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(errno,MSG) ) )
421 #define ZYPP_THROW_ERRNO_MSG1(EXCPTTYPE, ERRNO,MSG)\
422 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(ERRNO,MSG) ) )
428 #endif // ZYPP_BASE_EXCEPTION_H
Base class for Exception.
static std::string strErrno(int errno_r)
Make a string from errno_r.
void do_ZYPP_CAUGHT(const TExcpt &excpt_r, const CodeLocation &where_r)
Helper for ZYPP_THROW( Exception ).
CodeLocation(const std::string &file_r, const std::string &func_r, unsigned line_r)
Ctor.
typename std::enable_if< !std::is_base_of< Exception, TExcpt >::value, int >::type EnableIfNotException
SFINAE: Hide template signature if TExcpt is derived from Exception.
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.
void addHistory(const std::string &msg_r)
Add some message text to the history.
HistorySize historySize() const
The size of the history list.
void do_ZYPP_RETHROW(const TExcpt &excpt_r, const CodeLocation &where_r) __attribute__((noreturn))
Helper for ZYPP_THROW( Exception ).
virtual const char * what() const
Return message string.
static void log(const Exception &excpt_r, const CodeLocation &where_r, const char *const prefix_r)
Drop a logline on throw, catch or rethrow.
std::string asUserString() const
Translated error message as string suitable for the user.
void remember(const Exception &old_r)
Store an other Exception as history.
std::string asString() const
Error message provided by dumpOn as string.
void moveToHistory(TContainer &&msgc_r)
addHistory from string container types (oldest first) moving
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
HistoryIterator historyBegin() const
Iterator pointing to the most recent message.
const CodeLocation & where() const
Return CodeLocation.
std::list< std::string > History
bool historyEmpty() const
Whether the history list is empty.
friend std::ostream & operator<<(std::ostream &str, const CodeLocation &obj)
Easy-to use interface to the ZYPP dependency resolver.
std::string historyAsString() const
The history as string.
virtual ~Exception()
Dtor.
std::string asString() const
Location as string.
typename std::enable_if< std::is_base_of< Exception, TExcpt >::value, int >::type EnableIfIsException
SFINAE: Hide template signature unless TExcpt is derived from Exception.
exception_detail::CodeLocation CodeLocation
std::ostream & operator<<(std::ostream &str, const Exception &obj)
friend std::ostream & operator<<(std::ostream &str, const Exception &obj)
std::ostream & dumpError(std::ostream &str) const
Called by std::ostream & operator<<.
History::size_type HistorySize
void relocate(const CodeLocation &where_r) const
Exchange location on rethrow.
String related utilities and Regular expression matching.
HistoryIterator historyEnd() const
Iterator pointing behind the last message.
History::const_iterator HistoryIterator
void addToHistory(const TContainer &msgc_r)
addHistory from string container types (oldest first)
void do_ZYPP_THROW(const TExcpt &excpt_r, const CodeLocation &where_r) __attribute__((noreturn))
Helper for ZYPP_THROW( Exception ).
const std::string & msg() const
Return the message string provided to the ctor.
Keep FILE, FUNCTION and LINE.