15#include <zypp-core/base/Logger.h>
16#include <zypp-core/base/LogTools.h>
17#include <zypp-core/base/Gettext.h>
18#include <zypp-core/base/StringV.h>
19#include <zypp-core/base/Exception.h>
27 namespace exception_detail
53 : _msg(
std::move(msg_r) )
61 : _msg(
std::move(msg_r) )
66 {
remember( std::move(history_r) ); }
69 : _msg(
std::move(msg_r) )
70 {
remember( std::move(history_r) ); }
77 std::ostringstream
str;
84 std::ostringstream
str;
88 return _(
str.str().c_str());
107 if ( &old_r !=
this )
117 if ( &old_r !=
this )
119 History & newh( old_r._history );
120 newh.push_front( old_r.asUserString() );
129 std::rethrow_exception(old_r);
133 }
catch (
const std::exception& e ) {
144 {
_history.push_front( std::move(msg_r) ); }
148 std::ostringstream ret;
150 ret <<
_(
"History:") << endl;
151 for (
const std::string & entry :
_history ) {
152 strv::split( entry,
"\n", [&ret]( std::string_view line_r,
unsigned idx,
bool last_r ) ->
void {
153 if ( not ( last_r && line_r.empty() ) )
154 ret << (idx==0?
" - ":
" ") << line_r << endl;
175 {
return strErrno( errno_r, std::string(msg_r) ); }
180 return msg_r +=
strErrno( errno_r );
184 const char *
const prefix_r )
186 INT << where_r <<
" " << prefix_r <<
" " << excpt_r.
asUserHistory() << endl;
190 const char *
const prefix_r )
192 INT << where_r <<
" " << prefix_r <<
" exception of type " << typename_r << endl;
Base class for Exception.
static std::string strErrno(int errno_r)
Make a string from errno_r.
virtual ~Exception()
Dtor.
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
std::ostream & dumpError(std::ostream &str) const
Called by std::ostream & operator<<.
std::string asUserString() const
Translated error message as string suitable for the user.
void addHistory(const std::string &msg_r)
Add some message text to the history.
std::string historyAsString() const
The history as string.
virtual std::ostream & dumpOn(std::ostream &str) const
Overload this to print a proper error message.
std::string asString() const
Error message provided by dumpOn as 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::list< std::string > History
virtual const char * what() const
Return message string.
bool historyEmpty() const
Whether the history list is empty.
void remember(const Exception &old_r)
Store an other Exception as history.
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &str, const CodeLocation &obj)
std::string strerror(int errno_r)
Return string describing the error_r code.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Keep FILE, FUNCTION and LINE.
std::string asString() const
Location as string.