12 #ifndef ZYPP_BASE_EXCEPTION_H 13 #define ZYPP_BASE_EXCEPTION_H 20 #include <type_traits> 28 namespace exception_detail
69 #define ZYPP_EX_CODELOCATION ::zypp::exception_detail::CodeLocation(( *__FILE__ == '/' ? strrchr( __FILE__, '/' ) + 1 : __FILE__ ),__FUNCTION__,__LINE__) 72 std::ostream &
operator<<( std::ostream &
str,
const CodeLocation & obj );
195 { _where = where_r; }
199 { _where = std::move(where_r); }
206 const std::string &
msg()
const 227 void remember(
const Exception & old_r );
232 void remember( std::exception_ptr old_r );
239 { addHistory( msg_r ); }
242 { addHistory( std::move(msg_r) ); }
245 void addHistory(
const std::string & msg_r );
247 void addHistory( std::string && msg_r );
250 template<
class TContainer>
253 for (
const std::string & el : msgc_r )
257 template<
class TContainer>
260 for ( std::string & el : msgc_r )
261 addHistory( std::move(el) );
266 {
return _history.begin(); }
270 {
return _history.end(); }
274 {
return _history.empty(); }
278 {
return _history.size(); }
290 std::string historyAsString()
const;
293 std::string asUserHistory()
const;
299 virtual std::ostream &
dumpOn( std::ostream &
str )
const;
303 static std::string strErrno(
int errno_r );
305 static std::string strErrno(
int errno_r, std::string msg_r );
311 static void log(
const Exception & excpt_r,
const CodeLocation & where_r,
312 const char *
const prefix_r );
314 static void log(
const char * typename_r,
const CodeLocation & where_r,
315 const char *
const prefix_r );
322 const char *
what()
const throw()
override 323 {
return _msg.c_str(); }
329 std::ostream & dumpError( std::ostream &
str )
const;
340 namespace exception_detail
343 template<
class TExcpt>
347 template<
class TExcpt>
352 template<
class TExcpt, EnableIfIsException<TExcpt> = 0>
354 template<
class TExcpt, EnableIfIsException<TExcpt>>
357 excpt_r.relocate( where_r );
362 template<
class TExcpt, EnableIfIsException<TExcpt> = 0>
364 template<
class TExcpt, EnableIfIsException<TExcpt>>
368 excpt_r.relocate(std::move(where_r) );
373 template<
class TExcpt, EnableIfNotException<TExcpt> = 0>
375 template<
class TExcpt, EnableIfNotException<TExcpt>>
376 void do_ZYPP_THROW(
const TExcpt & excpt_r,
const CodeLocation & where_r )
383 template<
class TExcpt, EnableIfIsException<TExcpt> = 0>
390 template<
class TExcpt, EnableIfNotException<TExcpt> = 0>
391 void do_ZYPP_CAUGHT(
const TExcpt & excpt_r,
const CodeLocation & where_r )
397 void do_ZYPP_CAUGHT (
const std::exception_ptr & excpt_r, CodeLocation &&where_r );
401 template<
class TExcpt, EnableIfIsException<TExcpt> = 0>
403 template<
class TExcpt, EnableIfIsException<TExcpt>>
407 excpt_r.relocate( where_r );
411 template<
class TExcpt, EnableIfIsException<TExcpt> = 0>
413 template<
class TExcpt, EnableIfIsException<TExcpt>>
417 excpt_r.relocate( std::move(where_r) );
422 template<
class TExcpt, EnableIfNotException<TExcpt> = 0>
424 template<
class TExcpt, EnableIfNotException<TExcpt>>
425 void do_ZYPP_RETHROW(
const TExcpt & excpt_r,
const CodeLocation & where_r )
431 void do_ZYPP_RETHROW(
const std::exception_ptr & excpt_r,
const CodeLocation & where_r );
434 template<
class TExcpt>
439 excpt_r.relocate( std::move(where_r) );
441 Exception::log(
typeid(excpt_r).name(), where_r,
"THROW (EXCPTR): " );
443 return std::make_exception_ptr<std::decay_t<TExcpt>>( std::forward<TExcpt>(excpt_r) );
447 std::exception_ptr
do_ZYPP_FWD_EXCPT_PTR(
const std::exception_ptr & excpt_r, CodeLocation &&where_r );
459 #define ZYPP_THROW(EXCPT)\ 460 ::zypp::exception_detail::do_ZYPP_THROW( EXCPT, ZYPP_EX_CODELOCATION ) 463 #define ZYPP_EXCPT_PTR(EXCPT)\ 464 ::zypp::exception_detail::do_ZYPP_EXCPT_PTR( EXCPT, ZYPP_EX_CODELOCATION ) 467 #define ZYPP_FWD_EXCPT(EXCPT)\ 468 ::zypp::exception_detail::do_ZYPP_FWD_EXCPT_PTR( EXCPT, ZYPP_EX_CODELOCATION ) 471 #define ZYPP_FWD_CURRENT_EXCPT()\ 472 ::zypp::exception_detail::do_ZYPP_FWD_EXCPT_PTR( std::current_exception(), ZYPP_EX_CODELOCATION ) 475 #define ZYPP_CAUGHT(EXCPT)\ 476 ::zypp::exception_detail::do_ZYPP_CAUGHT( EXCPT, ZYPP_EX_CODELOCATION ) 479 #define ZYPP_RETHROW(EXCPT)\ 480 ::zypp::exception_detail::do_ZYPP_RETHROW( EXCPT, ZYPP_EX_CODELOCATION ) 484 #define ZYPP_THROW_MSG(EXCPTTYPE, MSG)\ 485 ZYPP_THROW( EXCPTTYPE( MSG ) ) 488 #define ZYPP_THROW_ERRNO(EXCPTTYPE)\ 489 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(errno) ) ) 492 #define ZYPP_THROW_ERRNO1(EXCPTTYPE, ERRNO)\ 493 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(ERRNO) ) ) 496 #define ZYPP_THROW_ERRNO_MSG(EXCPTTYPE, MSG)\ 497 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(errno,MSG) ) ) 500 #define ZYPP_THROW_ERRNO_MSG1(EXCPTTYPE, ERRNO,MSG)\ 501 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(ERRNO,MSG) ) ) 507 #endif // ZYPP_BASE_EXCEPTION_H std::string asString(const Patch::Category &obj)
HistoryIterator historyEnd() const
Iterator pointing behind the last message.
void addToHistory(const TContainer &msgc_r)
addHistory from string container types (oldest first)
void relocate(CodeLocation &&where_r) const
Exchange location on rethrow.
std::exception_ptr do_ZYPP_FWD_EXCPT_PTR(const std::exception_ptr &excpt_r, CodeLocation &&where_r)
Helper for ZYPP_FWD_CURRENT_EXCPT().
void do_ZYPP_RETHROW(const std::exception_ptr &excpt_r, const CodeLocation &where_r)
std::ostream & operator<<(std::ostream &str, const CodeLocation &obj)
void do_ZYPP_CAUGHT(const std::exception_ptr &excpt_r, CodeLocation &&where_r)
Helper for std::exception_ptr.
History::size_type HistorySize
constexpr bool is_base_of_v
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
std::enable_if_t< std::is_base_of_v< Exception, TExcpt >, int > EnableIfIsException
SFINAE: Hide template signature unless TExcpt is derived from Exception.
std::string asUserString(VendorSupportOption opt)
converts the support option to a name intended to be printed to the user.
HistorySize historySize() const
The size of the history list.
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.
typename enable_if< B, T >::type enable_if_t
History::const_iterator HistoryIterator
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
friend std::ostream & operator<<(std::ostream &str, const CodeLocation &obj)
std::enable_if_t< !std::is_base_of_v< Exception, TExcpt >, int > EnableIfNotException
SFINAE: Hide template signature if TExcpt is derived from Exception.
bool historyEmpty() const
Whether the history list is empty.
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
CodeLocation & operator=(const CodeLocation &)=default
CodeLocation(std::string file_r, std::string func_r, unsigned line_r)
Ctor.
void remember(const std::string &msg_r)
Remembering a plain string is most probably not wanted - we addHistory.
const char * what() const override
Return message string.
void remember(std::string &&msg_r)
Base class for Exception.
void do_ZYPP_THROW(const TExcpt &excpt_r, const CodeLocation &where_r) __attribute__((noreturn))
Helper for ZYPP_THROW( Exception ).
Keep FILE, FUNCTION and LINE.
typename decay< T >::type decay_t
std::list< std::string > History
void relocate(const CodeLocation &where_r) const
Exchange location on rethrow.
Easy-to use interface to the ZYPP dependency resolver.
std::exception_ptr do_ZYPP_EXCPT_PTR(TExcpt &&excpt_r, CodeLocation &&where_r)
Helper for ZYPP_EXCPT_PTR( Exception ).
std::string asString() const
Location as string.
const std::string & msg() const
Return the message string provided to the ctor.