From b887f14d96d68102a216129261886ad9d166c1e6 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 6 Feb 2013 12:51:12 +0100 Subject: [PATCH] Use BOOST_THROW_EXCEPTION instead of boost::throw_exception() Fixes #3636 --- components/checker/checkercomponent.cpp | 2 +- components/compat/compatcomponent.cpp | 14 +- .../replication/replicationcomponent.cpp | 2 +- icinga-app/icinga.cpp | 2 +- lib/base/application.cpp | 22 +-- lib/base/asynctask.h | 4 +- lib/base/component.cpp | 6 +- lib/base/dictionary.cpp | 2 +- lib/base/dynamicobject.cpp | 12 +- lib/base/dynamictype.cpp | 2 +- lib/base/fifo.cpp | 2 +- lib/base/i2-base.h | 3 +- lib/base/logger.cpp | 14 +- lib/base/netstring.cpp | 12 +- lib/base/object.cpp | 2 +- lib/base/process.cpp | 2 +- lib/base/socket.cpp | 24 +-- lib/base/streamlogger.cpp | 2 +- lib/base/tcpsocket.cpp | 8 +- lib/base/tlsstream.cpp | 10 +- lib/base/unixsocket.cpp | 6 +- lib/base/utility.cpp | 42 ++--- lib/base/value.cpp | 6 +- lib/base/value.h | 4 +- lib/config/config_parser.cc | 6 +- lib/config/config_parser.yy | 6 +- lib/config/configcompiler.cpp | 4 +- lib/config/configitem.cpp | 4 +- lib/config/configitembuilder.cpp | 6 +- lib/config/configtype.cpp | 2 +- lib/config/expression.cpp | 12 +- lib/icinga/externalcommandprocessor.cpp | 176 +++++++++--------- lib/icinga/host.cpp | 8 +- lib/icinga/hostgroup.cpp | 2 +- lib/icinga/macroprocessor.cpp | 4 +- lib/icinga/nullchecktask.cpp | 2 +- lib/icinga/pluginchecktask.cpp | 4 +- lib/icinga/service.cpp | 8 +- lib/icinga/servicegroup.cpp | 2 +- lib/icinga/timeperiod.cpp | 2 +- lib/remoting/endpoint.cpp | 6 +- lib/remoting/endpointmanager.cpp | 12 +- lib/remoting/jsonrpcconnection.cpp | 4 +- 43 files changed, 236 insertions(+), 239 deletions(-) diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index be154436d..af6e83a4b 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -108,7 +108,7 @@ void CheckerComponent::CheckTimerHandler(void) try { service->BeginExecuteCheck(boost::bind(&CheckerComponent::CheckCompletedHandler, this, service)); } catch (const exception& ex) { - Logger::Write(LogCritical, "checker", "Exception occured while checking service '" + service->GetName() + "': " + ex.what()); + Logger::Write(LogCritical, "checker", "Exception occured while checking service '" + service->GetName() + "': " + diagnostic_information(ex)); } tasks++; diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index fa4aa1b2c..2ded037a3 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -104,25 +104,25 @@ void CompatComponent::CommandPipeThread(const String& commandPath) fifo_ok = true; } else { if (unlink(commandPath.CStr()) < 0) - throw_exception(PosixException("unlink() failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("unlink() failed", errno)); } } if (!fifo_ok && mkfifo(commandPath.CStr(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0) - throw_exception(PosixException("mkfifo() failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("mkfifo() failed", errno)); for (;;) { int fd = open(commandPath.CStr(), O_RDONLY); if (fd < 0) - throw_exception(PosixException("open() failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("open() failed", errno)); FILE *fp = fdopen(fd, "r"); if (fp == NULL) { close(fd); - throw_exception(PosixException("fdopen() failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("fdopen() failed", errno)); } char line[2048]; @@ -149,7 +149,7 @@ void CompatComponent::ProcessCommand(const String& command) ExternalCommandProcessor::Execute(command); } catch (const exception& ex) { stringstream msgbuf; - msgbuf << "External command failed: " << ex.what(); + msgbuf << "External command failed: " << diagnostic_information(ex); Logger::Write(LogWarning, "compat", msgbuf.str()); } } @@ -503,11 +503,11 @@ void CompatComponent::StatusTimerHandler(void) statusfp.close(); if (rename(statuspathtmp.CStr(), statuspath.CStr()) < 0) - throw_exception(PosixException("rename() failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("rename() failed", errno)); objectfp.close(); if (rename(objectspathtmp.CStr(), objectspath.CStr()) < 0) - throw_exception(PosixException("rename() failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("rename() failed", errno)); } EXPORT_COMPONENT(compat, CompatComponent); diff --git a/components/replication/replicationcomponent.cpp b/components/replication/replicationcomponent.cpp index f8cfec823..fee1d2a96 100644 --- a/components/replication/replicationcomponent.cpp +++ b/components/replication/replicationcomponent.cpp @@ -217,7 +217,7 @@ void ReplicationComponent::RemoteObjectUpdateHandler(const RequestMessage& reque object->Register(); } else { if (object->IsLocal()) - throw_exception(invalid_argument("Replicated remote object is marked as local.")); + BOOST_THROW_EXCEPTION(invalid_argument("Replicated remote object is marked as local.")); // TODO: disallow config updates depending on endpoint config diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index d22ec6ead..b12f8a117 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -255,7 +255,7 @@ int main(int argc, char **argv) Application::Ptr app = Application::GetInstance(); if (!app) - throw_exception(runtime_error("Configuration must create an Application object.")); + BOOST_THROW_EXCEPTION(runtime_error("Configuration must create an Application object.")); if (g_AppParams.count("daemonize")) { Logger::Write(LogInformation, "icinga", "Daemonizing."); diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 31d87abd0..dcc4e5a70 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -37,7 +37,7 @@ Application::Application(const Dictionary::Ptr& serializedUpdate) : DynamicObject(serializedUpdate), m_PidFile(NULL) { if (!IsLocal()) - throw_exception(runtime_error("Application objects must be local.")); + BOOST_THROW_EXCEPTION(runtime_error("Application objects must be local.")); #ifdef _WIN32 /* disable GUI-based error messages for LoadLibrary() */ @@ -45,7 +45,7 @@ Application::Application(const Dictionary::Ptr& serializedUpdate) WSADATA wsaData; if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) - throw_exception(Win32Exception("WSAStartup failed", WSAGetLastError())); + BOOST_THROW_EXCEPTION(Win32Exception("WSAStartup failed", WSAGetLastError())); #endif /* _WIN32 */ char *debugging = getenv("_DEBUG"); @@ -205,7 +205,7 @@ String Application::GetExePath(const String& argv0) #ifndef _WIN32 char buffer[MAXPATHLEN]; if (getcwd(buffer, sizeof(buffer)) == NULL) - throw_exception(PosixException("getcwd failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("getcwd failed", errno)); String workingDirectory = buffer; if (argv0[0] != '/') @@ -240,20 +240,20 @@ String Application::GetExePath(const String& argv0) if (!foundPath) { executablePath.Clear(); - throw_exception(runtime_error("Could not determine executable path.")); + BOOST_THROW_EXCEPTION(runtime_error("Could not determine executable path.")); } } } if (realpath(executablePath.CStr(), buffer) == NULL) - throw_exception(PosixException("realpath failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("realpath failed", errno)); return buffer; #else /* _WIN32 */ char FullExePath[MAXPATHLEN]; if (!GetModuleFileName(NULL, FullExePath, sizeof(FullExePath))) - throw_exception(Win32Exception("GetModuleFileName() failed", GetLastError())); + BOOST_THROW_EXCEPTION(Win32Exception("GetModuleFileName() failed", GetLastError())); return FullExePath; #endif /* _WIN32 */ @@ -375,12 +375,8 @@ void Application::ExceptionHandler(void) try { throw; } catch (const std::exception& ex) { - std::cerr << std::endl; - std::cerr << "Unhandled exception of type " - << Utility::GetTypeName(typeid(ex)) - << std::endl; - std::cerr << "Diagnostic Information: " - << ex.what() + std::cerr << std::endl + << diagnostic_information(ex) << std::endl; } @@ -460,7 +456,7 @@ void Application::UpdatePidFile(const String& filename) m_PidFile = fopen(filename.CStr(), "w"); if (m_PidFile == NULL) - throw_exception(runtime_error("Could not open PID file '" + filename + "'")); + BOOST_THROW_EXCEPTION(runtime_error("Could not open PID file '" + filename + "'")); #ifndef _WIN32 if (flock(fileno(m_PidFile), LOCK_EX | LOCK_NB) < 0) { diff --git a/lib/base/asynctask.h b/lib/base/asynctask.h index 503fcf48a..ca0f8b3d6 100644 --- a/lib/base/asynctask.h +++ b/lib/base/asynctask.h @@ -91,10 +91,10 @@ public: TResult GetResult(void) { if (!m_Finished) - throw_exception(runtime_error("GetResult called on an unfinished AsyncTask")); + BOOST_THROW_EXCEPTION(runtime_error("GetResult called on an unfinished AsyncTask")); if (m_ResultRetrieved) - throw_exception(runtime_error("GetResult called on an AsyncTask whose result was already retrieved.")); + BOOST_THROW_EXCEPTION(runtime_error("GetResult called on an AsyncTask whose result was already retrieved.")); m_ResultRetrieved = true; diff --git a/lib/base/component.cpp b/lib/base/component.cpp index 928cca446..f60ed4f6c 100644 --- a/lib/base/component.cpp +++ b/lib/base/component.cpp @@ -32,7 +32,7 @@ Component::Component(const Dictionary::Ptr& properties) assert(Application::IsMainThread()); if (!IsLocal()) - throw_exception(runtime_error("Component objects must be local.")); + BOOST_THROW_EXCEPTION(runtime_error("Component objects must be local.")); #ifdef _WIN32 HMODULE @@ -63,14 +63,14 @@ Component::Component(const Dictionary::Ptr& properties) try { if (pCreateComponent == NULL) - throw_exception(runtime_error("Loadable module does not contain " + BOOST_THROW_EXCEPTION(runtime_error("Loadable module does not contain " "CreateComponent function")); /* pCreateComponent returns a raw pointer which we must wrap in a shared_ptr */ impl = IComponent::Ptr(pCreateComponent()); if (!impl) - throw_exception(runtime_error("CreateComponent function returned NULL.")); + BOOST_THROW_EXCEPTION(runtime_error("CreateComponent function returned NULL.")); } catch (...) { #ifdef _WIN32 FreeLibrary(hModule); diff --git a/lib/base/dictionary.cpp b/lib/base/dictionary.cpp index 9306b3fbc..78dbadaa2 100644 --- a/lib/base/dictionary.cpp +++ b/lib/base/dictionary.cpp @@ -223,7 +223,7 @@ Dictionary::Ptr Dictionary::FromJson(cJSON *json) Dictionary::Ptr dictionary = boost::make_shared(); if (json->type != cJSON_Object) - throw_exception(invalid_argument("JSON type must be cJSON_Object.")); + BOOST_THROW_EXCEPTION(invalid_argument("JSON type must be cJSON_Object.")); for (cJSON *i = json->child; i != NULL; i = i->next) { dictionary->Set(i->string, Value::FromJson(i)); diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index f4f9e765f..71f812403 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -39,7 +39,7 @@ DynamicObject::DynamicObject(const Dictionary::Ptr& serializedObject) RegisterAttribute("methods", Attribute_Config); if (!serializedObject->Contains("configTx")) - throw_exception(invalid_argument("Serialized object must contain a config snapshot.")); + BOOST_THROW_EXCEPTION(invalid_argument("Serialized object must contain a config snapshot.")); /* apply config state from the config item/remote update; * The DynamicObject::Create function takes care of restoring @@ -173,7 +173,7 @@ void DynamicObject::InternalSetAttribute(const String& name, const Value& data, Value oldValue; if (!allowEditConfig && (tt.first->second.Type & Attribute_Config)) - throw_exception(runtime_error("Config properties are immutable: '" + name + "'.")); + BOOST_THROW_EXCEPTION(runtime_error("Config properties are immutable: '" + name + "'.")); if (!tt.second && tx >= tt.first->second.Tx) { oldValue = tt.first->second.Data; @@ -312,7 +312,7 @@ ScriptTask::Ptr DynamicObject::InvokeMethod(const String& method, ScriptFunction::Ptr func = ScriptFunction::GetByName(funcName); if (!func) - throw_exception(invalid_argument("Function '" + funcName + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("Function '" + funcName + "' does not exist.")); ScriptTask::Ptr task = boost::make_shared(func, arguments); task->Start(callback); @@ -330,7 +330,7 @@ void DynamicObject::DumpObjects(const String& filename) fp.open(tempFilename.CStr(), std::ios_base::out); if (!fp) - throw_exception(runtime_error("Could not open '" + filename + "' file")); + BOOST_THROW_EXCEPTION(runtime_error("Could not open '" + filename + "' file")); StdioStream::Ptr sfp = boost::make_shared(&fp, false); sfp->Start(); @@ -377,7 +377,7 @@ void DynamicObject::DumpObjects(const String& filename) #endif /* _WIN32 */ if (rename(tempFilename.CStr(), filename.CStr()) < 0) - throw_exception(PosixException("rename() failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("rename() failed", errno)); } void DynamicObject::RestoreObjects(const String& filename) @@ -405,7 +405,7 @@ void DynamicObject::RestoreObjects(const String& filename) DynamicType::Ptr dt = DynamicType::GetByName(type); if (!dt) - throw_exception(invalid_argument("Invalid type: " + type)); + BOOST_THROW_EXCEPTION(invalid_argument("Invalid type: " + type)); DynamicObject::Ptr object = dt->GetObject(name); diff --git a/lib/base/dynamictype.cpp b/lib/base/dynamictype.cpp index 083288589..05efe7b5a 100644 --- a/lib/base/dynamictype.cpp +++ b/lib/base/dynamictype.cpp @@ -74,7 +74,7 @@ DynamicObject::Ptr DynamicType::GetObject(const String& name) const void DynamicType::RegisterType(const DynamicType::Ptr& type) { if (GetByName(type->GetName())) - throw_exception(runtime_error("Cannot register class for type '" + + BOOST_THROW_EXCEPTION(runtime_error("Cannot register class for type '" + type->GetName() + "': Objects of this type already exist.")); GetTypes()[type->GetName()] = type; diff --git a/lib/base/fifo.cpp b/lib/base/fifo.cpp index 6af65b8f2..33701d323 100644 --- a/lib/base/fifo.cpp +++ b/lib/base/fifo.cpp @@ -60,7 +60,7 @@ void FIFO::ResizeBuffer(size_t newSize) char *newBuffer = static_cast(realloc(m_Buffer, newSize)); if (newBuffer == NULL) - throw_exception(bad_alloc()); + BOOST_THROW_EXCEPTION(bad_alloc()); m_Buffer = newBuffer; diff --git a/lib/base/i2-base.h b/lib/base/i2-base.h index c48b007ae..66ee13c82 100644 --- a/lib/base/i2-base.h +++ b/lib/base/i2-base.h @@ -138,6 +138,7 @@ using std::type_info; #include #include #include +#include using boost::shared_ptr; using boost::weak_ptr; @@ -151,9 +152,9 @@ using boost::condition_variable; using boost::system_time; using boost::posix_time::millisec; using boost::tie; -using boost::throw_exception; using boost::rethrow_exception; using boost::current_exception; +using boost::diagnostic_information; namespace tuples = boost::tuples; diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp index 95af4c214..95f7ebc0f 100644 --- a/lib/base/logger.cpp +++ b/lib/base/logger.cpp @@ -32,11 +32,11 @@ Logger::Logger(const Dictionary::Ptr& properties) : DynamicObject(properties) { if (!IsLocal()) - throw_exception(runtime_error("Logger objects must be local.")); + BOOST_THROW_EXCEPTION(runtime_error("Logger objects must be local.")); String type = Get("type"); if (type.IsEmpty()) - throw_exception(runtime_error("Logger objects must have a 'type' property.")); + BOOST_THROW_EXCEPTION(runtime_error("Logger objects must have a 'type' property.")); ILogger::Ptr impl; @@ -44,12 +44,12 @@ Logger::Logger(const Dictionary::Ptr& properties) #ifndef _WIN32 impl = boost::make_shared(); #else /* _WIN32 */ - throw_exception(invalid_argument("Syslog is not supported on Windows.")); + BOOST_THROW_EXCEPTION(invalid_argument("Syslog is not supported on Windows.")); #endif /* _WIN32 */ } else if (type == "file") { String path = Get("path"); if (path.IsEmpty()) - throw_exception(invalid_argument("'log' object of type 'file' must have a 'path' property")); + BOOST_THROW_EXCEPTION(invalid_argument("'log' object of type 'file' must have a 'path' property")); StreamLogger::Ptr slogger = boost::make_shared(); slogger->OpenFile(path); @@ -58,7 +58,7 @@ Logger::Logger(const Dictionary::Ptr& properties) } else if (type == "console") { impl = boost::make_shared(&std::cout); } else { - throw_exception(runtime_error("Unknown log type: " + type)); + BOOST_THROW_EXCEPTION(runtime_error("Unknown log type: " + type)); } impl->m_Config = this; @@ -150,7 +150,7 @@ String Logger::SeverityToString(LogSeverity severity) case LogCritical: return "critical"; default: - throw_exception(invalid_argument("Invalid severity.")); + BOOST_THROW_EXCEPTION(invalid_argument("Invalid severity.")); } } @@ -170,7 +170,7 @@ LogSeverity Logger::StringToSeverity(const String& severity) else if (severity == "critical") return LogCritical; else - throw_exception(invalid_argument("Invalid severity: " + severity)); + BOOST_THROW_EXCEPTION(invalid_argument("Invalid severity: " + severity)); } /** diff --git a/lib/base/netstring.cpp b/lib/base/netstring.cpp index c3264d178..692c7754e 100644 --- a/lib/base/netstring.cpp +++ b/lib/base/netstring.cpp @@ -37,7 +37,7 @@ bool NetString::ReadStringFromStream(const Stream::Ptr& stream, String *str) char *buffer = static_cast(malloc(buffer_length)); if (buffer == NULL) - throw_exception(bad_alloc()); + BOOST_THROW_EXCEPTION(bad_alloc()); peek_length = stream->Peek(buffer, buffer_length); @@ -50,7 +50,7 @@ bool NetString::ReadStringFromStream(const Stream::Ptr& stream, String *str) /* no leading zeros allowed */ if (buffer[0] == '0' && isdigit(buffer[1])) { free(buffer); - throw_exception(invalid_argument("Invalid netString (leading zero)")); + BOOST_THROW_EXCEPTION(invalid_argument("Invalid netString (leading zero)")); } size_t len, i; @@ -60,7 +60,7 @@ bool NetString::ReadStringFromStream(const Stream::Ptr& stream, String *str) /* length specifier must have at most 9 characters */ if (i >= 9) { free(buffer); - throw_exception(invalid_argument("Length specifier must not exceed 9 characters")); + BOOST_THROW_EXCEPTION(invalid_argument("Length specifier must not exceed 9 characters")); } len = len * 10 + (buffer[i] - '0'); @@ -73,7 +73,7 @@ bool NetString::ReadStringFromStream(const Stream::Ptr& stream, String *str) if (new_buffer == NULL) { free(buffer); - throw_exception(bad_alloc()); + BOOST_THROW_EXCEPTION(bad_alloc()); } buffer = new_buffer; @@ -86,13 +86,13 @@ bool NetString::ReadStringFromStream(const Stream::Ptr& stream, String *str) /* check for the colon delimiter */ if (buffer[i] != ':') { free(buffer); - throw_exception(invalid_argument("Invalid NetString (missing :)")); + BOOST_THROW_EXCEPTION(invalid_argument("Invalid NetString (missing :)")); } /* check for the comma delimiter after the String */ if (buffer[i + 1 + len] != ',') { free(buffer); - throw_exception(invalid_argument("Invalid NetString (missing ,)")); + BOOST_THROW_EXCEPTION(invalid_argument("Invalid NetString (missing ,)")); } *str = String(&buffer[i + 1], &buffer[i + 1 + len]); diff --git a/lib/base/object.cpp b/lib/base/object.cpp index 5e7486b49..041c5418e 100644 --- a/lib/base/object.cpp +++ b/lib/base/object.cpp @@ -116,7 +116,7 @@ void Object::PrintMemoryProfile(void) dictfp.close(); if (rename("dictionaries.dump.tmp", "dictionaries.dump") < 0) - throw_exception(PosixException("rename() failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("rename() failed", errno)); String type; int count; diff --git a/lib/base/process.cpp b/lib/base/process.cpp index 63c24117e..1f76f3832 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -152,7 +152,7 @@ void Process::InitTask(void) #endif /* _MSC_VER */ if (m_FP == NULL) - throw_exception(runtime_error("Could not create process.")); + BOOST_THROW_EXCEPTION(runtime_error("Could not create process.")); } bool Process::RunTask(void) diff --git a/lib/base/socket.cpp b/lib/base/socket.cpp index e73582cb6..8e59b3b80 100644 --- a/lib/base/socket.cpp +++ b/lib/base/socket.cpp @@ -74,10 +74,10 @@ void Socket::SetFD(SOCKET fd) int flags; flags = fcntl(fd, F_GETFL, 0); if (flags < 0) - throw_exception(PosixException("fcntl failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno)); if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) - throw_exception(PosixException("fcntl failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno)); #else /* F_GETFL */ unsigned long lTrue = 1; ioctlsocket(fd, FIONBIO, &lTrue); @@ -154,7 +154,7 @@ int Socket::GetLastSocketError(void) */ void Socket::HandleException(void) { - throw_exception(SocketException("select() returned fd in except fdset", GetError())); + BOOST_THROW_EXCEPTION(SocketException("select() returned fd in except fdset", GetError())); } /** @@ -169,7 +169,7 @@ String Socket::GetAddressFromSockaddr(sockaddr *address, socklen_t len) if (getnameinfo(address, len, host, sizeof(host), service, sizeof(service), NI_NUMERICHOST | NI_NUMERICSERV) < 0) - throw_exception(SocketException("getnameinfo() failed", + BOOST_THROW_EXCEPTION(SocketException("getnameinfo() failed", GetLastSocketError())); stringstream s; @@ -190,7 +190,7 @@ String Socket::GetClientAddress(void) socklen_t len = sizeof(sin); if (getsockname(GetFD(), (sockaddr *)&sin, &len) < 0) - throw_exception(SocketException("getsockname() failed", GetError())); + BOOST_THROW_EXCEPTION(SocketException("getsockname() failed", GetError())); return GetAddressFromSockaddr((sockaddr *)&sin, len); } @@ -208,7 +208,7 @@ String Socket::GetPeerAddress(void) socklen_t len = sizeof(sin); if (getpeername(GetFD(), (sockaddr *)&sin, &len) < 0) - throw_exception(SocketException("getpeername() failed", GetError())); + BOOST_THROW_EXCEPTION(SocketException("getpeername() failed", GetError())); return GetAddressFromSockaddr((sockaddr *)&sin, len); } @@ -269,7 +269,7 @@ void Socket::ReadThreadProc(void) try { if (rc < 0) - throw_exception(SocketException("select() failed", GetError())); + BOOST_THROW_EXCEPTION(SocketException("select() failed", GetError())); if (FD_ISSET(fd, &readfds)) HandleReadable(); @@ -327,7 +327,7 @@ void Socket::WriteThreadProc(void) try { if (rc < 0) - throw_exception(SocketException("select() failed", GetError())); + BOOST_THROW_EXCEPTION(SocketException("select() failed", GetError())); if (FD_ISSET(fd, &writefds)) HandleWritable(); @@ -446,7 +446,7 @@ void Socket::Write(const void *buffer, size_t size) void Socket::Listen(void) { if (listen(GetFD(), SOMAXCONN) < 0) - throw_exception(SocketException("listen() failed", GetError())); + BOOST_THROW_EXCEPTION(SocketException("listen() failed", GetError())); m_Listening = true; } @@ -497,7 +497,7 @@ void Socket::HandleWritableClient(void) rc = send(GetFD(), data, count, 0); if (rc <= 0) - throw_exception(SocketException("send() failed", GetError())); + BOOST_THROW_EXCEPTION(SocketException("send() failed", GetError())); { boost::mutex::scoped_lock lock(m_QueueMutex); @@ -528,7 +528,7 @@ void Socket::HandleReadableClient(void) break; if (rc <= 0) - throw_exception(SocketException("recv() failed", GetError())); + BOOST_THROW_EXCEPTION(SocketException("recv() failed", GetError())); { boost::mutex::scoped_lock lock(m_QueueMutex); @@ -561,7 +561,7 @@ void Socket::HandleReadableServer(void) fd = accept(GetFD(), (sockaddr *)&addr, &addrlen); if (fd < 0) - throw_exception(SocketException("accept() failed", GetError())); + BOOST_THROW_EXCEPTION(SocketException("accept() failed", GetError())); TcpSocket::Ptr client = boost::make_shared(); client->SetFD(fd); diff --git a/lib/base/streamlogger.cpp b/lib/base/streamlogger.cpp index 89508dcfe..28042fdfb 100644 --- a/lib/base/streamlogger.cpp +++ b/lib/base/streamlogger.cpp @@ -54,7 +54,7 @@ void StreamLogger::OpenFile(const String& filename) stream->open(filename.CStr(), fstream::out | fstream::trunc); if (!stream->good()) - throw_exception(runtime_error("Could not open logfile '" + filename + "'")); + BOOST_THROW_EXCEPTION(runtime_error("Could not open logfile '" + filename + "'")); } catch (...) { delete stream; throw; diff --git a/lib/base/tcpsocket.cpp b/lib/base/tcpsocket.cpp index c42499211..a235ce6c6 100644 --- a/lib/base/tcpsocket.cpp +++ b/lib/base/tcpsocket.cpp @@ -52,7 +52,7 @@ void TcpSocket::Bind(String node, String service, int family) if (getaddrinfo(node.IsEmpty() ? NULL : node.CStr(), service.CStr(), &hints, &result) < 0) - throw_exception(SocketException("getaddrinfo() failed", GetLastSocketError())); + BOOST_THROW_EXCEPTION(SocketException("getaddrinfo() failed", GetLastSocketError())); int fd = INVALID_SOCKET; @@ -91,7 +91,7 @@ void TcpSocket::Bind(String node, String service, int family) freeaddrinfo(result); if (fd == INVALID_SOCKET) - throw_exception(runtime_error("Could not create a suitable socket.")); + BOOST_THROW_EXCEPTION(runtime_error("Could not create a suitable socket.")); } /** @@ -113,7 +113,7 @@ void TcpSocket::Connect(const String& node, const String& service) int rc = getaddrinfo(node.CStr(), service.CStr(), &hints, &result); if (rc < 0) - throw_exception(SocketException("getaddrinfo() failed", GetLastSocketError())); + BOOST_THROW_EXCEPTION(SocketException("getaddrinfo() failed", GetLastSocketError())); int fd = INVALID_SOCKET; @@ -149,5 +149,5 @@ void TcpSocket::Connect(const String& node, const String& service) freeaddrinfo(result); if (fd == INVALID_SOCKET) - throw_exception(runtime_error("Could not create a suitable socket.")); + BOOST_THROW_EXCEPTION(runtime_error("Could not create a suitable socket.")); } diff --git a/lib/base/tlsstream.cpp b/lib/base/tlsstream.cpp index b8f46c771..c3e16b5a6 100644 --- a/lib/base/tlsstream.cpp +++ b/lib/base/tlsstream.cpp @@ -47,10 +47,10 @@ void TlsStream::Start(void) m_SSLContext.reset(); if (!m_SSL) - throw_exception(OpenSSLException("SSL_new failed", ERR_get_error())); + BOOST_THROW_EXCEPTION(OpenSSLException("SSL_new failed", ERR_get_error())); if (!GetClientCertificate()) - throw_exception(logic_error("No X509 client certificate was specified.")); + BOOST_THROW_EXCEPTION(logic_error("No X509 client certificate was specified.")); if (!m_SSLIndexInitialized) { m_SSLIndex = SSL_get_ex_new_index(0, const_cast("TlsStream"), NULL, NULL, NULL); @@ -142,7 +142,7 @@ void TlsStream::HandleIO(void) return; default: I2Stream_check_exception(m_BIO); - throw_exception(OpenSSLException("SSL_do_handshake failed", ERR_get_error())); + BOOST_THROW_EXCEPTION(OpenSSLException("SSL_do_handshake failed", ERR_get_error())); } } } @@ -167,7 +167,7 @@ void TlsStream::HandleIO(void) return; default: I2Stream_check_exception(m_BIO); - throw_exception(OpenSSLException("SSL_read failed", ERR_get_error())); + BOOST_THROW_EXCEPTION(OpenSSLException("SSL_read failed", ERR_get_error())); } } } @@ -201,7 +201,7 @@ void TlsStream::HandleIO(void) return; default: I2Stream_check_exception(m_BIO); - throw_exception(OpenSSLException("SSL_write failed", ERR_get_error())); + BOOST_THROW_EXCEPTION(OpenSSLException("SSL_write failed", ERR_get_error())); } } } diff --git a/lib/base/unixsocket.cpp b/lib/base/unixsocket.cpp index 8cf7ea277..f8ad65d5f 100644 --- a/lib/base/unixsocket.cpp +++ b/lib/base/unixsocket.cpp @@ -27,7 +27,7 @@ UnixSocket::UnixSocket(void) int fd = socket(AF_UNIX, SOCK_STREAM, PF_UNIX); if (fd < 0) - throw_exception(PosixException("socket() failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("socket() failed", errno)); SetFD(fd); } @@ -43,7 +43,7 @@ void UnixSocket::Bind(const String& path) sun.sun_path[sizeof(sun.sun_path) - 1] = '\0'; if (bind(GetFD(), (sockaddr *)&sun, SUN_LEN(&sun)) < 0) - throw_exception(PosixException("bind() failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("bind() failed", errno)); } void UnixSocket::Connect(const String& path) @@ -55,6 +55,6 @@ void UnixSocket::Connect(const String& path) sun.sun_path[sizeof(sun.sun_path) - 1] = '\0'; if (connect(GetFD(), (sockaddr *)&sun, SUN_LEN(&sun)) < 0 && errno != EINPROGRESS) - throw_exception(PosixException("connect() failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("connect() failed", errno)); } #endif /* _WIN32 */ diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index 615ee3a82..49707a7e1 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -121,7 +121,7 @@ void Utility::Daemonize(void) { pid = fork(); if (pid < 0) - throw_exception(PosixException("fork() failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("fork() failed", errno)); if (pid) _exit(0); @@ -129,7 +129,7 @@ void Utility::Daemonize(void) { fd = open("/dev/null", O_RDWR); if (fd < 0) - throw_exception(PosixException("open() failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("open() failed", errno)); if (fd != STDIN_FILENO) dup2(fd, STDIN_FILENO); @@ -144,7 +144,7 @@ void Utility::Daemonize(void) { close(fd); if (setsid() < 0) - throw_exception(PosixException("setsid() failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("setsid() failed", errno)); #endif } @@ -179,19 +179,19 @@ shared_ptr Utility::MakeSSLContext(const String& pubkey, const String& SSL_CTX_set_mode(sslContext.get(), SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); if (!SSL_CTX_use_certificate_chain_file(sslContext.get(), pubkey.CStr())) - throw_exception(OpenSSLException("Could not load public X509 key file", ERR_get_error())); + BOOST_THROW_EXCEPTION(OpenSSLException("Could not load public X509 key file", ERR_get_error())); if (!SSL_CTX_use_PrivateKey_file(sslContext.get(), privkey.CStr(), SSL_FILETYPE_PEM)) - throw_exception(OpenSSLException("Could not load private X509 key file", ERR_get_error())); + BOOST_THROW_EXCEPTION(OpenSSLException("Could not load private X509 key file", ERR_get_error())); if (!SSL_CTX_load_verify_locations(sslContext.get(), cakey.CStr(), NULL)) - throw_exception(OpenSSLException("Could not load public CA key file", ERR_get_error())); + BOOST_THROW_EXCEPTION(OpenSSLException("Could not load public CA key file", ERR_get_error())); STACK_OF(X509_NAME) *cert_names; cert_names = SSL_load_client_CA_file(cakey.CStr()); if (cert_names == NULL) - throw_exception(OpenSSLException("SSL_load_client_CA_file() failed", ERR_get_error())); + BOOST_THROW_EXCEPTION(OpenSSLException("SSL_load_client_CA_file() failed", ERR_get_error())); SSL_CTX_set_client_CA_list(sslContext.get(), cert_names); @@ -212,7 +212,7 @@ String Utility::GetCertificateCN(const shared_ptr& certificate) NID_commonName, buffer, sizeof(buffer)); if (rc == -1) - throw_exception(OpenSSLException("X509 certificate has no CN" + BOOST_THROW_EXCEPTION(OpenSSLException("X509 certificate has no CN" " attribute", ERR_get_error())); return buffer; @@ -230,16 +230,16 @@ shared_ptr Utility::GetX509Certificate(const String& pemfile) BIO *fpcert = BIO_new(BIO_s_file()); if (fpcert == NULL) - throw_exception(OpenSSLException("BIO_new failed", + BOOST_THROW_EXCEPTION(OpenSSLException("BIO_new failed", ERR_get_error())); if (BIO_read_filename(fpcert, pemfile.CStr()) < 0) - throw_exception(OpenSSLException("BIO_read_filename failed", + BOOST_THROW_EXCEPTION(OpenSSLException("BIO_read_filename failed", ERR_get_error())); cert = PEM_read_bio_X509_AUX(fpcert, NULL, NULL, NULL); if (cert == NULL) - throw_exception(OpenSSLException("PEM_read_bio_X509_AUX failed", + BOOST_THROW_EXCEPTION(OpenSSLException("PEM_read_bio_X509_AUX failed", ERR_get_error())); BIO_free(fpcert); @@ -271,14 +271,14 @@ String Utility::DirName(const String& path) String result; if (dir == NULL) - throw_exception(bad_alloc()); + BOOST_THROW_EXCEPTION(bad_alloc()); #ifndef _WIN32 result = dirname(dir); #else /* _WIN32 */ if (!PathRemoveFileSpec(dir)) { free(dir); - throw_exception(Win32Exception("PathRemoveFileSpec() failed", + BOOST_THROW_EXCEPTION(Win32Exception("PathRemoveFileSpec() failed", GetLastError())); } @@ -305,7 +305,7 @@ String Utility::BaseName(const String& path) String result; if (dir == NULL) - throw_exception(bad_alloc()); + BOOST_THROW_EXCEPTION(bad_alloc()); #ifndef _WIN32 result = basename(dir); @@ -356,7 +356,7 @@ double Utility::GetTime(void) struct timeval tv; if (gettimeofday(&tv, NULL) < 0) - throw_exception(PosixException("gettimeofday() failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("gettimeofday() failed", errno)); return tv.tv_sec + tv.tv_usec / 1000000.0; #endif /* _WIN32 */ @@ -418,12 +418,12 @@ Utility::LoadIcingaLibrary(const String& library, bool module) HMODULE hModule = LoadLibrary(path.CStr()); if (hModule == NULL) - throw_exception(Win32Exception("LoadLibrary('" + path + "') failed", GetLastError())); + BOOST_THROW_EXCEPTION(Win32Exception("LoadLibrary('" + path + "') failed", GetLastError())); #else /* _WIN32 */ lt_dlhandle hModule = lt_dlopen(path.CStr()); if (hModule == NULL) { - throw_exception(runtime_error("Could not load library '" + path + "': " + lt_dlerror())); + BOOST_THROW_EXCEPTION(runtime_error("Could not load library '" + path + "': " + lt_dlerror())); } #endif /* _WIN32 */ @@ -460,7 +460,7 @@ bool Utility::Glob(const String& pathSpec, const function& if (errorCode == ERROR_FILE_NOT_FOUND) return false; - throw_exception(Win32Exception("FindFirstFile() failed", errorCode)); + BOOST_THROW_EXCEPTION(Win32Exception("FindFirstFile() failed", errorCode)); } do { @@ -468,7 +468,7 @@ bool Utility::Glob(const String& pathSpec, const function& } while (FindNextFile(handle, &wfd)); if (!FindClose(handle)) - throw_exception(Win32Exception("FindClose() failed", GetLastError())); + BOOST_THROW_EXCEPTION(Win32Exception("FindClose() failed", GetLastError())); return true; #else /* _WIN32 */ @@ -480,7 +480,7 @@ bool Utility::Glob(const String& pathSpec, const function& if (rc == GLOB_NOMATCH) return false; - throw_exception(PosixException("glob() failed", errno)); + BOOST_THROW_EXCEPTION(PosixException("glob() failed", errno)); } if (gr.gl_pathc == 0) { @@ -515,7 +515,7 @@ void Utility::WaitUntil(const function& predicate) * (like spawning a process) until the application instance * has been initialized. */ if (!instance) - throw_exception(runtime_error("Waiting for predicate failed: Application instance is not initialized.")); + BOOST_THROW_EXCEPTION(runtime_error("Waiting for predicate failed: Application instance is not initialized.")); instance->ProcessEvents(); } diff --git a/lib/base/value.cpp b/lib/base/value.cpp index a83a75739..53578fe82 100644 --- a/lib/base/value.cpp +++ b/lib/base/value.cpp @@ -74,7 +74,7 @@ Value Value::FromJson(cJSON *json) else if (json->type == cJSON_NULL) return Value(); else - throw_exception(invalid_argument("Unsupported JSON type.")); + BOOST_THROW_EXCEPTION(invalid_argument("Unsupported JSON type.")); } /** @@ -126,7 +126,7 @@ cJSON *Value::ToJson(void) const } else if (m_Value.type() == typeid(boost::blank)) { return cJSON_CreateNull(); } else { - throw_exception(runtime_error("Invalid variant type.")); + BOOST_THROW_EXCEPTION(runtime_error("Invalid variant type.")); } } @@ -141,7 +141,7 @@ Value Value::Deserialize(const String& jsonString) cJSON *json = cJSON_Parse(jsonString.CStr()); if (!json) - throw_exception(runtime_error("Invalid JSON String")); + BOOST_THROW_EXCEPTION(runtime_error("Invalid JSON String")); Value value = FromJson(json); cJSON_Delete(json); diff --git a/lib/base/value.h b/lib/base/value.h index 5c52e79cc..b6623d871 100644 --- a/lib/base/value.h +++ b/lib/base/value.h @@ -67,7 +67,7 @@ public: Object::Ptr object = dynamic_pointer_cast(value); if (!object) - throw_exception(invalid_argument("shared_ptr value type must inherit from Object class.")); + BOOST_THROW_EXCEPTION(invalid_argument("shared_ptr value type must inherit from Object class.")); m_Value = object; } @@ -103,7 +103,7 @@ public: shared_ptr object = dynamic_pointer_cast(boost::get(m_Value)); if (!object) - throw_exception(bad_cast()); + BOOST_THROW_EXCEPTION(bad_cast()); return object; } diff --git a/lib/config/config_parser.cc b/lib/config/config_parser.cc index 308597e95..5a915bae8 100644 --- a/lib/config/config_parser.cc +++ b/lib/config/config_parser.cc @@ -237,7 +237,7 @@ void yyerror(YYLTYPE *locp, ConfigCompiler *, const char *err) { stringstream message; message << *locp << ": " << err; - throw_exception(runtime_error(message.str())); + ConfigCompilerContext::GetContext()->AddError(false, message.str()); } int yyparse(ConfigCompiler *context); @@ -257,7 +257,7 @@ void ConfigCompiler::Compile(void) try { yyparse(this); } catch (const exception& ex) { - ConfigCompilerContext::GetContext()->AddError(false, ex.what()); + ConfigCompilerContext::GetContext()->AddError(false, boost::diagnostic_information(ex)); } } @@ -1671,7 +1671,7 @@ yyreduce: if (!m_Type) { if ((yyvsp[(1) - (3)].num)) - throw_exception(invalid_argument("partial type definition for unknown type '" + name + "'")); + BOOST_THROW_EXCEPTION(invalid_argument("Partial type definition for unknown type '" + name + "'")); m_Type = boost::make_shared(name, yylloc); ConfigCompilerContext::GetContext()->AddType(m_Type); diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy index 8bb83388f..e2de35958 100644 --- a/lib/config/config_parser.yy +++ b/lib/config/config_parser.yy @@ -87,7 +87,7 @@ void yyerror(YYLTYPE *locp, ConfigCompiler *, const char *err) { stringstream message; message << *locp << ": " << err; - throw_exception(runtime_error(message.str())); + ConfigCompilerContext::GetContext()->AddError(false, message.str()); } int yyparse(ConfigCompiler *context); @@ -107,7 +107,7 @@ void ConfigCompiler::Compile(void) try { yyparse(this); } catch (const exception& ex) { - ConfigCompilerContext::GetContext()->AddError(false, ex.what()); + ConfigCompilerContext::GetContext()->AddError(false, boost::diagnostic_information(ex)); } } @@ -151,7 +151,7 @@ type: partial_specifier T_TYPE identifier if (!m_Type) { if ($1) - throw_exception(invalid_argument("partial type definition for unknown type '" + name + "'")); + BOOST_THROW_EXCEPTION(invalid_argument("Partial type definition for unknown type '" + name + "'")); m_Type = boost::make_shared(name, yylloc); ConfigCompilerContext::GetContext()->AddType(m_Type); diff --git a/lib/config/configcompiler.cpp b/lib/config/configcompiler.cpp index a7f178c56..a499bb7f7 100644 --- a/lib/config/configcompiler.cpp +++ b/lib/config/configcompiler.cpp @@ -138,7 +138,7 @@ void ConfigCompiler::CompileFile(const String& path) stream.open(path.CStr(), ifstream::in); if (!stream) - throw_exception(invalid_argument("Could not open config file: " + path)); + BOOST_THROW_EXCEPTION(invalid_argument("Could not open config file: " + path)); Logger::Write(LogInformation, "config", "Compiling config file: " + path); @@ -195,7 +195,7 @@ void ConfigCompiler::HandleFileInclude(const String& include, bool search, if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CompileFile, _1))) { stringstream msgbuf; msgbuf << "Include file '" + include + "' does not exist (or no files found for pattern): " << debuginfo; - throw_exception(invalid_argument(msgbuf.str())); + BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str())); } } diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index f37261b2d..302dbe13b 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -125,7 +125,7 @@ void ConfigItem::InternalLink(const Dictionary::Ptr& dictionary) const stringstream message; message << "Parent object '" << name << "' does not" " exist (" << m_DebugInfo << ")"; - throw_exception(domain_error(message.str())); + BOOST_THROW_EXCEPTION(domain_error(message.str())); } parent->InternalLink(dictionary); @@ -169,7 +169,7 @@ DynamicObject::Ptr ConfigItem::Commit(void) DynamicType::Ptr dtype = DynamicType::GetByName(GetType()); if (!dtype) - throw_exception(runtime_error("Type '" + GetType() + "' does not exist.")); + BOOST_THROW_EXCEPTION(runtime_error("Type '" + GetType() + "' does not exist.")); if (!dobj) dobj = dtype->GetObject(GetName()); diff --git a/lib/config/configitembuilder.cpp b/lib/config/configitembuilder.cpp index 3111a23bf..dde8c8d94 100644 --- a/lib/config/configitembuilder.cpp +++ b/lib/config/configitembuilder.cpp @@ -90,19 +90,19 @@ ConfigItem::Ptr ConfigItemBuilder::Compile(void) if (m_Type.IsEmpty()) { stringstream msgbuf; msgbuf << "The type name of an object may not be empty: " << m_DebugInfo; - throw_exception(invalid_argument(msgbuf.str())); + BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str())); } if (!DynamicType::GetByName(m_Type)) { stringstream msgbuf; msgbuf << "The type '" + m_Type + "' is unknown: " << m_DebugInfo; - throw_exception(invalid_argument(msgbuf.str())); + BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str())); } if (m_Name.IsEmpty()) { stringstream msgbuf; msgbuf << "The name of an object may not be empty: " << m_DebugInfo; - throw_exception(invalid_argument(msgbuf.str())); + BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str())); } ExpressionList::Ptr exprl = boost::make_shared(); diff --git a/lib/config/configtype.cpp b/lib/config/configtype.cpp index f510630c2..52e57d6a6 100644 --- a/lib/config/configtype.cpp +++ b/lib/config/configtype.cpp @@ -117,7 +117,7 @@ void ConfigType::ValidateDictionary(const Dictionary::Ptr& dictionary, ScriptFunction::Ptr func = ScriptFunction::GetByName(validator); if (!func) - throw_exception(invalid_argument("Validator function '" + validator + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("Validator function '" + validator + "' does not exist.")); vector arguments; arguments.push_back(LocationToString(locations)); diff --git a/lib/config/expression.cpp b/lib/config/expression.cpp index 71a9c8894..3f777fe0d 100644 --- a/lib/config/expression.cpp +++ b/lib/config/expression.cpp @@ -46,7 +46,7 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const switch (m_Operator) { case OperatorExecute: if (!valueExprl) - throw_exception(invalid_argument("Operand for OperatorExecute must be an ExpressionList.")); + BOOST_THROW_EXCEPTION(invalid_argument("Operand for OperatorExecute must be an ExpressionList.")); valueExprl->Execute(dictionary); @@ -74,7 +74,7 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const " += (non-dictionary and" " dictionary) (" << m_DebugInfo << ")"; - throw_exception(domain_error(message.str())); + BOOST_THROW_EXCEPTION(domain_error(message.str())); } dict = boost::make_shared(); @@ -94,13 +94,13 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const stringstream message; message << "+= only works for dictionaries (" << m_DebugInfo << ")"; - throw_exception(domain_error(message.str())); + BOOST_THROW_EXCEPTION(domain_error(message.str())); } break; default: - throw_exception(runtime_error("Not yet implemented.")); + BOOST_THROW_EXCEPTION(runtime_error("Not yet implemented.")); } dictionary->Set(m_Key, newValue); @@ -154,7 +154,7 @@ void Expression::DumpValue(ostream& fp, int indent, const Value& value, bool inl return; } - throw_exception(runtime_error("Encountered unknown type while dumping value.")); + BOOST_THROW_EXCEPTION(runtime_error("Encountered unknown type while dumping value.")); } void Expression::Dump(ostream& fp, int indent) const @@ -177,7 +177,7 @@ void Expression::Dump(ostream& fp, int indent) const fp << "+="; break; default: - throw_exception(runtime_error("Not yet implemented.")); + BOOST_THROW_EXCEPTION(runtime_error("Not yet implemented.")); } fp << " "; diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index 110b147d8..59efb8aa5 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -30,12 +30,12 @@ void ExternalCommandProcessor::Execute(const String& line) return; if (line[0] != '[') - throw_exception(invalid_argument("Missing timestamp in command: " + line)); + BOOST_THROW_EXCEPTION(invalid_argument("Missing timestamp in command: " + line)); size_t pos = line.FindFirstOf("]"); if (pos == String::NPos) - throw_exception(invalid_argument("Missing timestamp in command: " + line)); + BOOST_THROW_EXCEPTION(invalid_argument("Missing timestamp in command: " + line)); String timestamp = line.SubStr(1, pos - 1); String args = line.SubStr(pos + 2, String::NPos); @@ -43,12 +43,12 @@ void ExternalCommandProcessor::Execute(const String& line) double ts = Convert::ToDouble(timestamp); if (ts == 0) - throw_exception(invalid_argument("Invalid timestamp in command: " + line)); + BOOST_THROW_EXCEPTION(invalid_argument("Invalid timestamp in command: " + line)); vector argv = args.Split(is_any_of(";")); if (argv.size() == 0) - throw_exception(invalid_argument("Missing arguments in command: " + line)); + BOOST_THROW_EXCEPTION(invalid_argument("Missing arguments in command: " + line)); vector argvExtra(argv.begin() + 1, argv.end()); Execute(ts, argv[0], argvExtra); @@ -107,7 +107,7 @@ void ExternalCommandProcessor::Execute(double time, const String& command, const it = m_Commands.find(command); if (it == m_Commands.end()) - throw_exception(invalid_argument("The external command '" + command + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The external command '" + command + "' does not exist.")); it->second(time, arguments); } @@ -120,15 +120,15 @@ void ExternalCommandProcessor::RegisterCommand(const String& command, const Exte void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const vector& arguments) { if (arguments.size() < 4) - throw_exception(invalid_argument("Expected 4 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 4 arguments.")); if (!Service::Exists(arguments[1])) - throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist.")); Service::Ptr service = Service::GetByName(arguments[1]); if (!service->GetEnablePassiveChecks()) - throw_exception(invalid_argument("Got passive check result for service '" + arguments[1] + "' which has passive checks disabled.")); + BOOST_THROW_EXCEPTION(invalid_argument("Got passive check result for service '" + arguments[1] + "' which has passive checks disabled.")); int exitStatus = Convert::ToDouble(arguments[2]); Dictionary::Ptr result = PluginCheckTask::ParseCheckOutput(arguments[3]); @@ -152,10 +152,10 @@ void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const vect void ExternalCommandProcessor::ScheduleSvcCheck(double, const vector& arguments) { if (arguments.size() < 3) - throw_exception(invalid_argument("Expected 3 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 3 arguments.")); if (!Service::Exists(arguments[1])) - throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist.")); Service::Ptr service = Service::GetByName(arguments[1]); @@ -174,10 +174,10 @@ void ExternalCommandProcessor::ScheduleSvcCheck(double, const vector& ar void ExternalCommandProcessor::ScheduleForcedSvcCheck(double, const vector& arguments) { if (arguments.size() < 3) - throw_exception(invalid_argument("Expected 3 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 3 arguments.")); if (!Service::Exists(arguments[1])) - throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist.")); Service::Ptr service = Service::GetByName(arguments[1]); @@ -189,10 +189,10 @@ void ExternalCommandProcessor::ScheduleForcedSvcCheck(double, const vector& arguments) { if (arguments.size() < 2) - throw_exception(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); if (!Service::Exists(arguments[1])) - throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist.")); Service::Ptr service = Service::GetByName(arguments[1]); @@ -203,10 +203,10 @@ void ExternalCommandProcessor::EnableSvcCheck(double, const vector& argu void ExternalCommandProcessor::DisableSvcCheck(double, const vector& arguments) { if (arguments.size() < 2) - throw_exception(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); if (!Service::Exists(arguments[1])) - throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist.")); Service::Ptr service = Service::GetByName(arguments[1]); @@ -223,10 +223,10 @@ void ExternalCommandProcessor::ShutdownProcess(double, const vector&) void ExternalCommandProcessor::ScheduleForcedHostSvcChecks(double, const vector& arguments) { if (arguments.size() < 2) - throw_exception(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); if (!Host::Exists(arguments[0])) - throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist.")); double planned_check = Convert::ToDouble(arguments[1]); @@ -242,10 +242,10 @@ void ExternalCommandProcessor::ScheduleForcedHostSvcChecks(double, const vector< void ExternalCommandProcessor::ScheduleHostSvcChecks(double, const vector& arguments) { if (arguments.size() < 2) - throw_exception(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); if (!Host::Exists(arguments[0])) - throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist.")); double planned_check = Convert::ToDouble(arguments[1]); @@ -266,10 +266,10 @@ void ExternalCommandProcessor::ScheduleHostSvcChecks(double, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); if (!Host::Exists(arguments[0])) - throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist.")); Host::Ptr host = Host::GetByName(arguments[0]); @@ -282,10 +282,10 @@ void ExternalCommandProcessor::EnableHostSvcChecks(double, const vector& void ExternalCommandProcessor::DisableHostSvcChecks(double, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Expected 1 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 arguments.")); if (!Host::Exists(arguments[0])) - throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist.")); Host::Ptr host = Host::GetByName(arguments[0]); @@ -298,17 +298,17 @@ void ExternalCommandProcessor::DisableHostSvcChecks(double, const vector void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const vector& arguments) { if (arguments.size() < 7) - throw_exception(invalid_argument("Expected 7 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 7 arguments.")); if (!Service::Exists(arguments[1])) - throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist.")); bool sticky = Convert::ToBool(arguments[2]); Service::Ptr service = Service::GetByName(arguments[1]); if (service->GetState() == StateOK) - throw_exception(invalid_argument("The service '" + arguments[1] + "' is OK.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' is OK.")); Logger::Write(LogInformation, "icinga", "Setting acknowledgement for service '" + service->GetName() + "'"); service->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal); @@ -318,10 +318,10 @@ void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const vector& arguments) { if (arguments.size() < 8) - throw_exception(invalid_argument("Expected 8 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments.")); if (!Service::Exists(arguments[1])) - throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist.")); bool sticky = Convert::ToBool(arguments[2]); double timestamp = Convert::ToDouble(arguments[5]); @@ -329,7 +329,7 @@ void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const vector< Service::Ptr service = Service::GetByName(arguments[1]); if (service->GetState() == StateOK) - throw_exception(invalid_argument("The service '" + arguments[1] + "' is OK.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' is OK.")); Logger::Write(LogInformation, "icinga", "Setting timed acknowledgement for service '" + service->GetName() + "'"); service->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal); @@ -339,10 +339,10 @@ void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const vector< void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const vector& arguments) { if (arguments.size() < 2) - throw_exception(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); if (!Service::Exists(arguments[1])) - throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist.")); Service::Ptr service = Service::GetByName(arguments[1]); @@ -354,17 +354,17 @@ void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const vector& arguments) { if (arguments.size() < 6) - throw_exception(invalid_argument("Expected 6 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 6 arguments.")); if (!Host::Exists(arguments[0])) - throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist.")); bool sticky = Convert::ToBool(arguments[0]); Host::Ptr host = Host::GetByName(arguments[0]); if (host->IsUp()) - throw_exception(invalid_argument("The host '" + arguments[0] + "' is OK.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' is OK.")); Logger::Write(LogInformation, "icinga", "Setting acknowledgement for host '" + host->GetName() + "'"); host->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal); @@ -374,10 +374,10 @@ void ExternalCommandProcessor::AcknowledgeHostProblem(double, const vector& arguments) { if (arguments.size() < 7) - throw_exception(invalid_argument("Expected 7 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 7 arguments.")); if (!Host::Exists(arguments[0])) - throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist.")); bool sticky = Convert::ToBool(arguments[1]); double timestamp = Convert::ToDouble(arguments[4]); @@ -385,7 +385,7 @@ void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const vector Host::Ptr host = Host::GetByName(arguments[0]); if (host->IsUp()) - throw_exception(invalid_argument("The host '" + arguments[0] + "' is OK.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' is OK.")); Logger::Write(LogInformation, "icinga", "Setting timed acknowledgement for host '" + host->GetName() + "'"); host->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal); @@ -395,10 +395,10 @@ void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const vector void ExternalCommandProcessor::RemoveHostAcknowledgement(double, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); if (!Host::Exists(arguments[0])) - throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist.")); Host::Ptr host = Host::GetByName(arguments[0]); @@ -410,10 +410,10 @@ void ExternalCommandProcessor::RemoveHostAcknowledgement(double, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); if (!HostGroup::Exists(arguments[0])) - throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host group '" + arguments[0] + "' does not exist.")); HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]); @@ -428,10 +428,10 @@ void ExternalCommandProcessor::EnableHostgroupSvcChecks(double, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); if (!HostGroup::Exists(arguments[0])) - throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host group '" + arguments[0] + "' does not exist.")); HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]); @@ -446,10 +446,10 @@ void ExternalCommandProcessor::DisableHostgroupSvcChecks(double, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); if (!ServiceGroup::Exists(arguments[0])) - throw_exception(invalid_argument("The service group '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service group '" + arguments[0] + "' does not exist.")); ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]); @@ -462,10 +462,10 @@ void ExternalCommandProcessor::EnableServicegroupSvcChecks(double, const vector< void ExternalCommandProcessor::DisableServicegroupSvcChecks(double, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); if (!ServiceGroup::Exists(arguments[0])) - throw_exception(invalid_argument("The service group '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service group '" + arguments[0] + "' does not exist.")); ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]); @@ -478,10 +478,10 @@ void ExternalCommandProcessor::DisableServicegroupSvcChecks(double, const vector void ExternalCommandProcessor::EnablePassiveSvcChecks(double, const vector& arguments) { if (arguments.size() < 2) - throw_exception(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); if (!Service::Exists(arguments[1])) - throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist.")); Service::Ptr service = Service::GetByName(arguments[1]); @@ -492,10 +492,10 @@ void ExternalCommandProcessor::EnablePassiveSvcChecks(double, const vector& arguments) { if (arguments.size() < 2) - throw_exception(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); if (!Service::Exists(arguments[1])) - throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist.")); Service::Ptr service = Service::GetByName(arguments[1]); @@ -506,10 +506,10 @@ void ExternalCommandProcessor::DisablePassiveSvcChecks(double, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); if (!ServiceGroup::Exists(arguments[0])) - throw_exception(invalid_argument("The service group '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service group '" + arguments[0] + "' does not exist.")); ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]); @@ -522,10 +522,10 @@ void ExternalCommandProcessor::EnableServicegroupPassiveSvcChecks(double, const void ExternalCommandProcessor::DisableServicegroupPassiveSvcChecks(double, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); if (!ServiceGroup::Exists(arguments[0])) - throw_exception(invalid_argument("The service group '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service group '" + arguments[0] + "' does not exist.")); ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]); @@ -538,10 +538,10 @@ void ExternalCommandProcessor::DisableServicegroupPassiveSvcChecks(double, const void ExternalCommandProcessor::EnableHostgroupPassiveSvcChecks(double, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); if (!HostGroup::Exists(arguments[0])) - throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host group '" + arguments[0] + "' does not exist.")); HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]); @@ -556,10 +556,10 @@ void ExternalCommandProcessor::EnableHostgroupPassiveSvcChecks(double, const vec void ExternalCommandProcessor::DisableHostgroupPassiveSvcChecks(double, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); if (!HostGroup::Exists(arguments[0])) - throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host group '" + arguments[0] + "' does not exist.")); HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]); @@ -574,7 +574,7 @@ void ExternalCommandProcessor::DisableHostgroupPassiveSvcChecks(double, const ve void ExternalCommandProcessor::ProcessFile(double, const vector& arguments) { if (arguments.size() < 2) - throw_exception(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); String file = arguments[0]; bool del = Convert::ToBool(arguments[1]); @@ -594,7 +594,7 @@ void ExternalCommandProcessor::ProcessFile(double, const vector& argumen Execute(line); } catch (const exception& ex) { stringstream msgbuf; - msgbuf << "External command failed: " << ex.what(); + msgbuf << "External command failed: " << diagnostic_information(ex); Logger::Write(LogWarning, "icinga", msgbuf.str()); } } @@ -608,10 +608,10 @@ void ExternalCommandProcessor::ProcessFile(double, const vector& argumen void ExternalCommandProcessor::ScheduleSvcDowntime(double, const vector& arguments) { if (arguments.size() < 9) - throw_exception(invalid_argument("Expected 9 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 9 arguments.")); if (!Service::Exists(arguments[1])) - throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist.")); Service::Ptr service = Service::GetByName(arguments[1]); @@ -629,7 +629,7 @@ void ExternalCommandProcessor::ScheduleSvcDowntime(double, const vector& void ExternalCommandProcessor::DelSvcDowntime(double, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); int id = Convert::ToLong(arguments[0]); Logger::Write(LogInformation, "icinga", "Removing downtime ID " + arguments[0]); @@ -640,10 +640,10 @@ void ExternalCommandProcessor::DelSvcDowntime(double, const vector& argu void ExternalCommandProcessor::ScheduleHostDowntime(double, const vector& arguments) { if (arguments.size() < 8) - throw_exception(invalid_argument("Expected 8 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments.")); if (!Host::Exists(arguments[0])) - throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist.")); Host::Ptr host = Host::GetByName(arguments[0]); @@ -661,7 +661,7 @@ void ExternalCommandProcessor::ScheduleHostDowntime(double, const vector void ExternalCommandProcessor::DelHostDowntime(double, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); int id = Convert::ToLong(arguments[0]); Logger::Write(LogInformation, "icinga", "Removing downtime ID " + arguments[0]); @@ -672,10 +672,10 @@ void ExternalCommandProcessor::DelHostDowntime(double, const vector& arg void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const vector& arguments) { if (arguments.size() < 8) - throw_exception(invalid_argument("Expected 8 argument.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 argument.")); if (!Host::Exists(arguments[0])) - throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist.")); Host::Ptr host = Host::GetByName(arguments[0]); @@ -700,10 +700,10 @@ void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const vector& arguments) { if (arguments.size() < 8) - throw_exception(invalid_argument("Expected 8 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments.")); if (!HostGroup::Exists(arguments[0])) - throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host group '" + arguments[0] + "' does not exist.")); HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]); @@ -723,10 +723,10 @@ void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double, const vecto void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const vector& arguments) { if (arguments.size() < 8) - throw_exception(invalid_argument("Expected 8 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments.")); if (!HostGroup::Exists(arguments[0])) - throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host group '" + arguments[0] + "' does not exist.")); HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]); @@ -758,10 +758,10 @@ void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const vector void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const vector& arguments) { if (arguments.size() < 8) - throw_exception(invalid_argument("Expected 8 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments.")); if (!ServiceGroup::Exists(arguments[0])) - throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host group '" + arguments[0] + "' does not exist.")); ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]); @@ -791,10 +791,10 @@ void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const ve void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double, const vector& arguments) { if (arguments.size() < 8) - throw_exception(invalid_argument("Expected 8 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments.")); if (!ServiceGroup::Exists(arguments[0])) - throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host group '" + arguments[0] + "' does not exist.")); ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]); @@ -814,10 +814,10 @@ void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double, const vec void ExternalCommandProcessor::AddHostComment(double, const vector& arguments) { if (arguments.size() < 4) - throw_exception(invalid_argument("Expected 4 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 4 arguments.")); if (!Host::Exists(arguments[0])) - throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist.")); Host::Ptr host = Host::GetByName(arguments[0]); @@ -828,7 +828,7 @@ void ExternalCommandProcessor::AddHostComment(double, const vector& argu void ExternalCommandProcessor::DelHostComment(double, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); int id = Convert::ToLong(arguments[0]); Logger::Write(LogInformation, "icinga", "Removing comment ID " + arguments[0]); @@ -839,10 +839,10 @@ void ExternalCommandProcessor::DelHostComment(double, const vector& argu void ExternalCommandProcessor::AddSvcComment(double, const vector& arguments) { if (arguments.size() < 5) - throw_exception(invalid_argument("Expected 5 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 5 arguments.")); if (!Service::Exists(arguments[1])) - throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist.")); Service::Ptr service = Service::GetByName(arguments[1]); @@ -853,7 +853,7 @@ void ExternalCommandProcessor::AddSvcComment(double, const vector& argum void ExternalCommandProcessor::DelSvcComment(double, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); int id = Convert::ToLong(arguments[0]); Logger::Write(LogInformation, "icinga", "Removing comment ID " + arguments[0]); @@ -865,10 +865,10 @@ void ExternalCommandProcessor::DelSvcComment(double, const vector& argum void ExternalCommandProcessor::DelAllHostComments(double, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); if (!Host::Exists(arguments[0])) - throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist.")); Host::Ptr host = Host::GetByName(arguments[0]); @@ -879,10 +879,10 @@ void ExternalCommandProcessor::DelAllHostComments(double, const vector& void ExternalCommandProcessor::DelAllSvcComments(double, const vector& arguments) { if (arguments.size() < 2) - throw_exception(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); if (!Service::Exists(arguments[1])) - throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist.")); Service::Ptr service = Service::GetByName(arguments[1]); diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index c0604d399..e3ac52799 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -76,7 +76,7 @@ Host::Ptr Host::GetByName(const String& name) DynamicObject::Ptr configObject = DynamicObject::GetObject("Host", name); if (!configObject) - throw_exception(invalid_argument("Host '" + name + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("Host '" + name + "' does not exist.")); return dynamic_pointer_cast(configObject); } @@ -270,7 +270,7 @@ void Host::ObjectCommittedHandler(const ConfigItem::Ptr& item) CopyServiceAttributes(host, service, builder); } else { - throw_exception(invalid_argument("Service description must be either a string or a dictionary.")); + BOOST_THROW_EXCEPTION(invalid_argument("Service description must be either a string or a dictionary.")); } ConfigItem::Ptr serviceItem = builder->Compile(); @@ -410,10 +410,10 @@ void Host::ValidateServicesCache(void) void Host::ValidateServiceDictionary(const ScriptTask::Ptr& task, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Missing argument: Location must be specified.")); + BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Location must be specified.")); if (arguments.size() < 2) - throw_exception(invalid_argument("Missing argument: Attribute dictionary must be specified.")); + BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Attribute dictionary must be specified.")); String location = arguments[0]; Dictionary::Ptr attrs = arguments[1]; diff --git a/lib/icinga/hostgroup.cpp b/lib/icinga/hostgroup.cpp index c79bb0429..137768c72 100644 --- a/lib/icinga/hostgroup.cpp +++ b/lib/icinga/hostgroup.cpp @@ -56,7 +56,7 @@ HostGroup::Ptr HostGroup::GetByName(const String& name) DynamicObject::Ptr configObject = DynamicObject::GetObject("HostGroup", name); if (!configObject) - throw_exception(invalid_argument("HostGroup '" + name + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("HostGroup '" + name + "' does not exist.")); return dynamic_pointer_cast(configObject); } diff --git a/lib/icinga/macroprocessor.cpp b/lib/icinga/macroprocessor.cpp index 93365aaa9..4561aab97 100644 --- a/lib/icinga/macroprocessor.cpp +++ b/lib/icinga/macroprocessor.cpp @@ -32,7 +32,7 @@ String MacroProcessor::ResolveMacros(const String& str, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Missing argument: Service must be specified.")); + BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Service must be specified.")); Dictionary::Ptr cr = boost::make_shared(); cr->Set("state", StateUnknown); diff --git a/lib/icinga/pluginchecktask.cpp b/lib/icinga/pluginchecktask.cpp index 39b643e17..28a362ee4 100644 --- a/lib/icinga/pluginchecktask.cpp +++ b/lib/icinga/pluginchecktask.cpp @@ -30,11 +30,11 @@ PluginCheckTask::PluginCheckTask(const ScriptTask::Ptr& task, const Process::Ptr void PluginCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector& arguments) { if (arguments.size() < 1) - throw_exception(invalid_argument("Missing argument: Service must be specified.")); + BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Service must be specified.")); Value vservice = arguments[0]; if (!vservice.IsObjectType()) - throw_exception(invalid_argument("Argument must be a config object.")); + BOOST_THROW_EXCEPTION(invalid_argument("Argument must be a config object.")); Service::Ptr service = static_cast(vservice); diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 1f4c3278d..dbd586771 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -87,7 +87,7 @@ Service::Ptr Service::GetByName(const String& name) DynamicObject::Ptr configObject = DynamicObject::GetObject("Service", name); if (!configObject) - throw_exception(invalid_argument("Service '" + name + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("Service '" + name + "' does not exist.")); return dynamic_pointer_cast(configObject); } @@ -97,7 +97,7 @@ Host::Ptr Service::GetHost(void) const String hostname = Get("host_name"); if (hostname.IsEmpty()) - throw_exception(runtime_error("Service object is missing the 'host_name' property.")); + BOOST_THROW_EXCEPTION(runtime_error("Service object is missing the 'host_name' property.")); return Host::GetByName(hostname); } @@ -290,7 +290,7 @@ double Service::GetNextCheck(void) value = Get("next_check"); if (value.IsEmpty()) - throw_exception(runtime_error("Failed to schedule next check.")); + BOOST_THROW_EXCEPTION(runtime_error("Failed to schedule next check.")); } return value; @@ -707,7 +707,7 @@ void Service::CheckCompletedHandler(const Dictionary::Ptr& scheduleInfo, } catch (const exception& ex) { stringstream msgbuf; msgbuf << "Exception occured during check for service '" - << GetName() << "': " << ex.what(); + << GetName() << "': " << diagnostic_information(ex); String message = msgbuf.str(); Logger::Write(LogWarning, "checker", message); diff --git a/lib/icinga/servicegroup.cpp b/lib/icinga/servicegroup.cpp index b59d882a4..7479a68cd 100644 --- a/lib/icinga/servicegroup.cpp +++ b/lib/icinga/servicegroup.cpp @@ -56,7 +56,7 @@ ServiceGroup::Ptr ServiceGroup::GetByName(const String& name) DynamicObject::Ptr configObject = DynamicObject::GetObject("ServiceGroup", name); if (!configObject) - throw_exception(invalid_argument("ServiceGroup '" + name + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("ServiceGroup '" + name + "' does not exist.")); return dynamic_pointer_cast(configObject); } diff --git a/lib/icinga/timeperiod.cpp b/lib/icinga/timeperiod.cpp index b46caef37..c68c67ce3 100644 --- a/lib/icinga/timeperiod.cpp +++ b/lib/icinga/timeperiod.cpp @@ -48,7 +48,7 @@ TimePeriod::Ptr TimePeriod::GetByName(const String& name) DynamicObject::Ptr configObject = DynamicObject::GetObject("TimePeriod", name); if (!configObject) - throw_exception(invalid_argument("TimePeriod '" + name + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("TimePeriod '" + name + "' does not exist.")); return dynamic_pointer_cast(configObject); } diff --git a/lib/remoting/endpoint.cpp b/lib/remoting/endpoint.cpp index c927fdb11..32659adb7 100644 --- a/lib/remoting/endpoint.cpp +++ b/lib/remoting/endpoint.cpp @@ -66,7 +66,7 @@ Endpoint::Ptr Endpoint::GetByName(const String& name) DynamicObject::Ptr configObject = DynamicObject::GetObject("Endpoint", name); if (!configObject) - throw_exception(invalid_argument("Endpoint '" + name + "' does not exist.")); + BOOST_THROW_EXCEPTION(invalid_argument("Endpoint '" + name + "' does not exist.")); return dynamic_pointer_cast(configObject); } @@ -224,7 +224,7 @@ void Endpoint::UnregisterTopicHandler(const String& topic, const functionCheckException(); } catch (const exception& ex) { stringstream message; - message << "Error occured for JSON-RPC socket: Message=" << ex.what(); + message << "Error occured for JSON-RPC socket: Message=" << diagnostic_information(ex); Logger::Write(LogWarning, "jsonrpc", message.str()); }*/ diff --git a/lib/remoting/endpointmanager.cpp b/lib/remoting/endpointmanager.cpp index 883b260ff..ebb90c795 100644 --- a/lib/remoting/endpointmanager.cpp +++ b/lib/remoting/endpointmanager.cpp @@ -104,7 +104,7 @@ void EndpointManager::AddListener(const String& service) shared_ptr sslContext = GetSSLContext(); if (!sslContext) - throw_exception(logic_error("SSL context is required for AddListener()")); + BOOST_THROW_EXCEPTION(logic_error("SSL context is required for AddListener()")); stringstream s; s << "Adding new listener: port " << service; @@ -131,7 +131,7 @@ void EndpointManager::AddConnection(const String& node, const String& service) { shared_ptr sslContext = GetSSLContext(); if (!sslContext) - throw_exception(logic_error("SSL context is required for AddConnection()")); + BOOST_THROW_EXCEPTION(logic_error("SSL context is required for AddConnection()")); TcpSocket::Ptr client = boost::make_shared(); client->Connect(node, service); @@ -229,7 +229,7 @@ void EndpointManager::SendAnycastMessage(const Endpoint::Ptr& sender, { String method; if (!message.GetMethod(&method)) - throw_exception(invalid_argument("Message is missing the 'method' property.")); + BOOST_THROW_EXCEPTION(invalid_argument("Message is missing the 'method' property.")); vector candidates; DynamicObject::Ptr object; @@ -273,11 +273,11 @@ void EndpointManager::SendMulticastMessage(const Endpoint::Ptr& sender, { String id; if (message.GetID(&id)) - throw_exception(invalid_argument("Multicast requests must not have an ID.")); + BOOST_THROW_EXCEPTION(invalid_argument("Multicast requests must not have an ID.")); String method; if (!message.GetMethod(&method)) - throw_exception(invalid_argument("Message is missing the 'method' property.")); + BOOST_THROW_EXCEPTION(invalid_argument("Message is missing the 'method' property.")); DynamicObject::Ptr object; BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Endpoint")->GetObjects()) { @@ -391,7 +391,7 @@ void EndpointManager::ProcessResponseMessage(const Endpoint::Ptr& sender, { String id; if (!message.GetID(&id)) - throw_exception(invalid_argument("Response message must have a message ID.")); + BOOST_THROW_EXCEPTION(invalid_argument("Response message must have a message ID.")); map::iterator it; it = m_Requests.find(id); diff --git a/lib/remoting/jsonrpcconnection.cpp b/lib/remoting/jsonrpcconnection.cpp index 22ec9744f..15fc68461 100644 --- a/lib/remoting/jsonrpcconnection.cpp +++ b/lib/remoting/jsonrpcconnection.cpp @@ -57,7 +57,7 @@ void JsonRpcConnection::ProcessData(void) Value value = Value::Deserialize(jsonString); if (!value.IsObjectType()) { - throw_exception(invalid_argument("JSON-RPC" + BOOST_THROW_EXCEPTION(invalid_argument("JSON-RPC" " message must be a dictionary.")); } @@ -65,7 +65,7 @@ void JsonRpcConnection::ProcessData(void) } catch (const exception& ex) { Logger::Write(LogCritical, "remoting", "Exception" " while processing message from JSON-RPC client: " + - String(ex.what())); + diagnostic_information(ex)); } } }