Skip to content

Commit

Permalink
Extract exception error info message.
Browse files Browse the repository at this point in the history
Refs #6070
  • Loading branch information
Michael Friedrich committed May 22, 2014
1 parent aaa6154 commit 0713918
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion components/db_ido_mysql/idomysqlconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ void IdoMysqlConnection::Pause(void)

void IdoMysqlConnection::ExceptionHandler(boost::exception_ptr exp)
{
Log(LogCritical, "db_ido_mysql", "Exception during database operation: " + DiagnosticInformation(exp));
Log(LogCritical, "db_ido_mysql", "Exception during database operation: '" + ErrorInformation(exp) + "'");
Log(LogDebug, "db_ido_mysql", "Exception during database operation: " + DiagnosticInformation(exp));

boost::mutex::scoped_lock lock(m_ConnectionMutex);

Expand Down
9 changes: 9 additions & 0 deletions lib/base/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,12 @@ String icinga::DiagnosticInformation(boost::exception_ptr eptr)

return boost::diagnostic_information(eptr);
}

String icinga::ErrorInformation(boost::exception_ptr eptr)
{
try {
boost::rethrow_exception(eptr);
} catch (const std::exception& ex) {
return ex.what();
}
}
11 changes: 11 additions & 0 deletions lib/base/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,18 @@ String DiagnosticInformation(const T& ex, StackTrace *stack = NULL, ContextTrace
return result.str();
}

template<typename T>
String ErrorInformation(const T& ex)
{
std::ostringstream result;

result << ex.what();

return result.str();
}

I2_BASE_API String DiagnosticInformation(boost::exception_ptr eptr);
I2_BASE_API String ErrorInformation(boost::exception_ptr eptr);

class I2_BASE_API posix_error : virtual public std::exception, virtual public boost::exception { };

Expand Down
2 changes: 1 addition & 1 deletion lib/remote/apilistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void ApiListener::AddConnection(const String& node, const String& service)
Utility::QueueAsyncCallback(boost::bind(&ApiListener::NewClientHandler, this, client, RoleClient));
} catch (const std::exception& ex) {
std::ostringstream info, debug;
info << "Cannot connect to host '" << node << "' on port '" << service << "'.";
info << "Cannot connect to host '" << node << "' on port '" << service << "'";
debug << info << std::endl << DiagnosticInformation(ex);
Log(LogCritical, "remote", info.str());
Log(LogDebug, "remote", debug.str());
Expand Down

0 comments on commit 0713918

Please sign in to comment.