Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions lib/base/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,40 +335,40 @@ void ScriptError::SetHandledByDebugger(bool handled)
m_HandledByDebugger = handled;
}

posix_error::~posix_error() throw()
const char* posix_error::what() const noexcept
{
free(m_Message);
}

const char *posix_error::what() const throw()
{
if (!m_Message) {
std::ostringstream msgbuf;

const char * const *func = boost::get_error_info<boost::errinfo_api_function>(*this);

if (func)
msgbuf << "Function call '" << *func << "'";
else
msgbuf << "Function call";

const std::string *fname = boost::get_error_info<boost::errinfo_file_name>(*this);
if (m_Message.IsEmpty()) {
try {
const char* const* func = boost::get_error_info<boost::errinfo_api_function>(*this);
if (func) {
m_Message += "Function call '" + std::string(*func) + "'";
} else {
m_Message += "Function call";
}

if (fname)
msgbuf << " for file '" << *fname << "'";
const std::string* fname = boost::get_error_info<boost::errinfo_file_name>(*this);

msgbuf << " failed";
if (fname) {
m_Message += " for file '" + *fname + "'";
}

const int *errnum = boost::get_error_info<boost::errinfo_errno>(*this);
m_Message += " failed";

if (errnum)
msgbuf << " with error code " << *errnum << ", '" << strerror(*errnum) << "'";
const int* errnum = boost::get_error_info<boost::errinfo_errno>(*this);

String str = msgbuf.str();
m_Message = strdup(str.CStr());
if (errnum) {
m_Message += " with error code " + std::to_string(*errnum) + ", '" + strerror(*errnum) + "'";
}
} catch (const std::bad_alloc&) {
m_Message.Clear();
return "Exception in 'posix_error::what()': bad_alloc";
} catch (...) {
m_Message.Clear();
return "Exception in 'posix_error::what()'";
Comment thread
Al2Klimov marked this conversation as resolved.
}
}

return m_Message;
return m_Message.CStr();
}

ValidationError::ValidationError(const ConfigObject::Ptr& object, const std::vector<String>& attributePath, const String& message)
Expand Down
6 changes: 2 additions & 4 deletions lib/base/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,10 @@ String DiagnosticInformation(const boost::exception_ptr& eptr, bool verbose = tr

class posix_error : virtual public std::exception, virtual public boost::exception {
public:
~posix_error() throw() override;

const char *what(void) const throw() final;
const char* what() const noexcept final;

private:
mutable char *m_Message{nullptr};
mutable String m_Message;
};

#ifdef _WIN32
Expand Down
Loading