12 #ifndef ZYPP_BASE_EXCEPTION_H 13 #define ZYPP_BASE_EXCEPTION_H 20 #include <type_traits> 28 namespace exception_detail
63 #define ZYPP_EX_CODELOCATION ::zypp::exception_detail::CodeLocation(( *__FILE__ == '/' ? strrchr( __FILE__, '/' ) + 1 : __FILE__ ),__FUNCTION__,__LINE__) 66 std::ostream &
operator<<( std::ostream &
str,
const CodeLocation & obj );
189 { _where = where_r; }
196 const std::string &
msg()
const 217 void remember(
const Exception & old_r );
222 void remember( std::exception_ptr old_r );
229 { addHistory( msg_r ); }
232 { addHistory( std::move(msg_r) ); }
235 void addHistory(
const std::string & msg_r );
237 void addHistory( std::string && msg_r );
240 template<
class TContainer>
243 for (
const std::string & el : msgc_r )
247 template<
class TContainer>
250 for ( std::string & el : msgc_r )
251 addHistory( std::move(el) );
256 {
return _history.begin(); }
260 {
return _history.end(); }
264 {
return _history.empty(); }
268 {
return _history.size(); }
280 std::string historyAsString()
const;
283 std::string asUserHistory()
const;
289 virtual std::ostream &
dumpOn( std::ostream &
str )
const;
293 static std::string strErrno(
int errno_r );
295 static std::string strErrno(
int errno_r, std::string msg_r );
301 static void log(
const Exception & excpt_r,
const CodeLocation & where_r,
302 const char *
const prefix_r );
304 static void log(
const char * typename_r,
const CodeLocation & where_r,
305 const char *
const prefix_r );
312 const char *
what()
const throw()
override 313 {
return _msg.c_str(); }
319 std::ostream & dumpError( std::ostream &
str )
const;
327 namespace exception_detail
330 template<
class TExcpt>
334 template<
class TExcpt>
339 template<
class TExcpt, EnableIfIsException<TExcpt> = 0>
341 template<
class TExcpt, EnableIfIsException<TExcpt>>
344 excpt_r.relocate( where_r );
350 template<
class TExcpt, EnableIfNotException<TExcpt> = 0>
352 template<
class TExcpt, EnableIfNotException<TExcpt>>
353 void do_ZYPP_THROW(
const TExcpt & excpt_r,
const CodeLocation & where_r )
361 template<
class TExcpt, EnableIfIsException<TExcpt> = 0>
368 template<
class TExcpt, EnableIfNotException<TExcpt> = 0>
369 void do_ZYPP_CAUGHT(
const TExcpt & excpt_r,
const CodeLocation & where_r )
376 template<
class TExcpt, EnableIfIsException<TExcpt> = 0>
378 template<
class TExcpt, EnableIfIsException<TExcpt>>
382 excpt_r.relocate( where_r );
387 template<
class TExcpt, EnableIfNotException<TExcpt> = 0>
389 template<
class TExcpt, EnableIfNotException<TExcpt>>
390 void do_ZYPP_RETHROW(
const TExcpt & excpt_r,
const CodeLocation & where_r )
396 void do_ZYPP_RETHROW(
const std::exception_ptr & excpt_r,
const CodeLocation & where_r );
399 template<
class TExcpt>
403 excpt_r.relocate( where_r );
406 Exception::log(
typeid(excpt_r).name(), where_r,
"THROW (EXCPTR): " );
408 return std::make_exception_ptr<std::decay_t<TExcpt>>( std::forward<TExcpt>(excpt_r) );
412 std::exception_ptr
do_ZYPP_FWD_EXCPT_PTR(
const std::exception_ptr & excpt_r,
const CodeLocation & where_r );
424 #define ZYPP_THROW(EXCPT)\ 425 ::zypp::exception_detail::do_ZYPP_THROW( EXCPT, ZYPP_EX_CODELOCATION ) 428 #define ZYPP_EXCPT_PTR(EXCPT)\ 429 ::zypp::exception_detail::do_ZYPP_EXCPT_PTR( EXCPT, ZYPP_EX_CODELOCATION ) 432 #define ZYPP_FWD_EXCPT(EXCPT)\ 433 ::zypp::exception_detail::do_ZYPP_FWD_EXCPT_PTR( EXCPT, ZYPP_EX_CODELOCATION ) 436 #define ZYPP_FWD_CURRENT_EXCPT()\ 437 ::zypp::exception_detail::do_ZYPP_FWD_EXCPT_PTR( std::current_exception(), ZYPP_EX_CODELOCATION ) 440 #define ZYPP_CAUGHT(EXCPT)\ 441 ::zypp::exception_detail::do_ZYPP_CAUGHT( EXCPT, ZYPP_EX_CODELOCATION ) 444 #define ZYPP_RETHROW(EXCPT)\ 445 ::zypp::exception_detail::do_ZYPP_RETHROW( EXCPT, ZYPP_EX_CODELOCATION ) 449 #define ZYPP_THROW_MSG(EXCPTTYPE, MSG)\ 450 ZYPP_THROW( EXCPTTYPE( MSG ) ) 453 #define ZYPP_THROW_ERRNO(EXCPTTYPE)\ 454 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(errno) ) ) 457 #define ZYPP_THROW_ERRNO1(EXCPTTYPE, ERRNO)\ 458 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(ERRNO) ) ) 461 #define ZYPP_THROW_ERRNO_MSG(EXCPTTYPE, MSG)\ 462 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(errno,MSG) ) ) 465 #define ZYPP_THROW_ERRNO_MSG1(EXCPTTYPE, ERRNO,MSG)\ 466 ZYPP_THROW( EXCPTTYPE( ::zypp::Exception::strErrno(ERRNO,MSG) ) ) 472 #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 do_ZYPP_CAUGHT(const TExcpt &excpt_r, const CodeLocation &where_r)
Helper for ZYPP_THROW( Exception ).
void do_ZYPP_RETHROW(const std::exception_ptr &excpt_r, const CodeLocation &where_r)
std::ostream & operator<<(std::ostream &str, const CodeLocation &obj)
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
std::exception_ptr do_ZYPP_FWD_EXCPT_PTR(const std::exception_ptr &excpt_r, const CodeLocation &where_r)
Helper for ZYPP_FWD_CURRENT_EXCPT().
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(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 ).
std::exception_ptr do_ZYPP_EXCPT_PTR(TExcpt &&excpt_r, const CodeLocation &where_r)
Helper for ZYPP_EXCPT_PTR( 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::string asString() const
Location as string.
const std::string & msg() const
Return the message string provided to the ctor.