]> granicus.if.org Git - icinga2/commitdiff
Use const-ref specifier when catching exceptions
authorGunnar Beutner <gunnar@beutner.name>
Mon, 25 Aug 2014 06:35:35 +0000 (08:35 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 25 Aug 2014 06:36:30 +0000 (08:36 +0200)
refs #6070

lib/base/application.cpp
lib/base/convert.hpp
lib/base/logger.cpp
lib/base/socket.cpp
lib/base/streamlogger.cpp
lib/base/tlsstream.cpp
lib/remote/apiclient.cpp
lib/remote/apilistener-sync.cpp
lib/remote/apilistener.cpp

index 49d2d39a079fbc6829d682f2cb03f6b3c223427f..0264f73245ba855a05f57e882f3a8f72af6b283b 100644 (file)
@@ -95,7 +95,7 @@ void Application::Stop(void)
        if (l_Restarting) {
                try {
                        UpdatePidFile(GetPidPath(), m_ReloadProcess);
-               } catch (std::exception&) {
+               } catch (const std::exception&) {
                        /* abort restart */
                        Log(LogCritical, "Application", "Cannot update PID file. Aborting restart operation.");
                        return;
@@ -667,7 +667,7 @@ int Application::Run(void)
 
        try {
                UpdatePidFile(GetPidPath());
-       } catch (std::exception&) {
+       } catch (const std::exception&) {
                Log(LogCritical, "Application", "Cannot update PID file '" + GetPidPath() + "'. Aborting.");
                return false;
        }
index 7d77abe933ce0a8043893540ee87a1c524f8e9e2..7a6db262858083f61c4c7a7a13558b4ee50ddfb8 100644 (file)
@@ -40,7 +40,7 @@ public:
        {
                try {
                        return boost::lexical_cast<long>(val);
-               } catch (std::exception&) {
+               } catch (const std::exception&) {
                        std::ostringstream msgbuf;
                        msgbuf << "Can't convert '" << val << "' to an integer.";
                        BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str()));
@@ -52,7 +52,7 @@ public:
        {
                try {
                        return boost::lexical_cast<double>(val);
-               } catch (std::exception&) {
+               } catch (const std::exception&) {
                        std::ostringstream msgbuf;
                        msgbuf << "Can't convert '" << val << "' to a floating point number.";
                        BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str()));
index ca1f9237a1c5d793f3f09de64dd1954d69784515..10ed3f842eccbe47ad1654dedfbb2dd7db96e847 100644 (file)
@@ -128,7 +128,7 @@ LogSeverity Logger::GetMinSeverity(void) const
 
                try {
                        ls = Logger::StringToSeverity(severity);
-               } catch (std::exception&) { /* use the default level */ }
+               } catch (const std::exception&) { /* use the default level */ }
 
                return ls;
        }
index 3156ac52e49f4aa3670f3037b45613f74b79e762..7d79980a98ec91542cb9d5dc418ac7638e23ccc8 100644 (file)
@@ -189,7 +189,7 @@ String Socket::GetClientAddress(void)
        String address;
        try {
                address = GetAddressFromSockaddr((sockaddr *)&sin, len);
-       } catch (std::exception&) {
+       } catch (const std::exception&) {
                /* already logged */
        }
 
@@ -231,7 +231,7 @@ String Socket::GetPeerAddress(void)
        String address;
        try {
                address = GetAddressFromSockaddr((sockaddr *)&sin, len);
-       } catch (std::exception&) {
+       } catch (const std::exception&) {
                /* already logged */
        }
 
index a7473b1fd71e6a06c33616b5d46dde50a9c5d101..a10682b71570b319b7f7f9eb182a075bd85b8171 100644 (file)
@@ -122,7 +122,7 @@ void StreamLogger::ProcessLogEntry(std::ostream& stream, bool tty, const LogEntr
 
        try {
                stream << Logger::SeverityToString(entry.Severity);
-       } catch (std::exception&) {
+       } catch (const std::exception&) {
                /* bail early */
                return;
        }
index 04b8104492f828a3c4a0dae49232b09fe454948a..cc1b304587b1cb6d202b172dd1dd36200bc5a513 100644 (file)
@@ -115,12 +115,12 @@ void TlsStream::Handshake(void)
                        case SSL_ERROR_WANT_READ:
                                try {
                                        m_Socket->Poll(true, false);
-                               } catch (std::exception&) {}
+                               } catch (const std::exception&) {}
                                continue;
                        case SSL_ERROR_WANT_WRITE:
                                try {
                                        m_Socket->Poll(false, true);
-                               } catch (std::exception&) {}
+                               } catch (const std::exception&) {}
                                continue;
                        case SSL_ERROR_ZERO_RETURN:
                                Close();
@@ -161,12 +161,12 @@ size_t TlsStream::Read(void *buffer, size_t count)
                                case SSL_ERROR_WANT_READ:
                                        try {
                                                m_Socket->Poll(true, false);
-                                       } catch (std::exception&) {}
+                                       } catch (const std::exception&) {}
                                        continue;
                                case SSL_ERROR_WANT_WRITE:
                                        try {
                                                m_Socket->Poll(false, true);
-                                       } catch (std::exception&) {}
+                                       } catch (const std::exception&) {}
                                        continue;
                                case SSL_ERROR_ZERO_RETURN:
                                        Close();
@@ -209,12 +209,12 @@ void TlsStream::Write(const void *buffer, size_t count)
                                case SSL_ERROR_WANT_READ:
                                        try {
                                                m_Socket->Poll(true, false);
-                                       } catch (std::exception&) {}
+                                       } catch (const std::exception&) {}
                                        continue;
                                case SSL_ERROR_WANT_WRITE:
                                        try {
                                                m_Socket->Poll(false, true);
-                                       } catch (std::exception&) {}
+                                       } catch (const std::exception&) {}
                                        continue;
                                case SSL_ERROR_ZERO_RETURN:
                                        Close();
@@ -258,12 +258,12 @@ void TlsStream::Close(void)
                        case SSL_ERROR_WANT_READ:
                                try {
                                        m_Socket->Poll(true, false);
-                               } catch (std::exception&) {}
+                               } catch (const std::exception&) {}
                                continue;
                        case SSL_ERROR_WANT_WRITE:
                                try {
                                        m_Socket->Poll(false, true);
-                               } catch (std::exception&) {}
+                               } catch (const std::exception&) {}
                                continue;
                        default:
                                goto close_socket;
index 0c0b17279675d5893082a202e0dc9f5b7ce614b9..498090ece8fc972e802e387755ff24430ff4b8c8 100644 (file)
@@ -155,7 +155,7 @@ bool ApiClient::ProcessMessage(void)
                        BOOST_THROW_EXCEPTION(std::invalid_argument("Function '" + method + "' does not exist."));
 
                resultMessage->Set("result", afunc->Invoke(origin, message->Get("params")));
-       } catch (std::exception& ex) {
+       } catch (const std::exception& ex) {
                resultMessage->Set("error", DiagnosticInformation(ex));
        }
 
index 62254c4b9c99501290f2bfd0cde631246f012c63..2dad6d6d5f8e29ff6179256dce1f11b4eda60a6c 100644 (file)
@@ -135,7 +135,7 @@ void ApiListener::SyncZoneDirs(void) const
 
                try {
                        SyncZoneDir(zone);
-               } catch (std::exception&) {
+               } catch (const std::exception&) {
                        continue;
                }
        }
index 0e133ccd41a5129d49c0d397918a637052ec1ef0..1ee95063001a31503a4d1f49bd429dedbbf3314a 100644 (file)
@@ -45,14 +45,14 @@ void ApiListener::OnConfigLoaded(void)
        shared_ptr<X509> cert = make_shared<X509>();
        try {
                cert = GetX509Certificate(GetCertPath());
-       } catch (std::exception&) {
+       } catch (const std::exception&) {
                Log(LogCritical, "ApiListener", "Cannot get certificate from cert path: '" + GetCertPath() + "'.");
                Application::Exit(EXIT_FAILURE);
        }
 
        try {
                SetIdentity(GetCertificateCN(cert));
-       } catch (std::exception&) {
+       } catch (const std::exception&) {
                Log(LogCritical, "ApiListener", "Cannot get certificate common name from cert path: '" + GetCertPath() + "'.");
                Application::Exit(EXIT_FAILURE);
        }
@@ -61,7 +61,7 @@ void ApiListener::OnConfigLoaded(void)
 
        try {
                m_SSLContext = MakeSSLContext(GetCertPath(), GetKeyPath(), GetCaPath());
-       } catch (std::exception&) {
+       } catch (const std::exception&) {
                Log(LogCritical, "ApiListener", "Cannot make SSL context for cert path: '" + GetCertPath() + "' key path: '" + GetKeyPath() + "' ca path: '" + GetCaPath() + "'.");
                Application::Exit(EXIT_FAILURE);
        }
@@ -69,7 +69,7 @@ void ApiListener::OnConfigLoaded(void)
        if (!GetCrlPath().IsEmpty()) {
                try {
                        AddCRLToSSLContext(m_SSLContext, GetCrlPath());
-               } catch (std::exception&) {
+               } catch (const std::exception&) {
                        Log(LogCritical, "ApiListener", "Cannot add certificate revocation list to SSL context for crl path: '" + GetCrlPath() + "'.");
                        Application::Exit(EXIT_FAILURE);
                }
@@ -205,7 +205,7 @@ void ApiListener::ListenerThreadProc(const Socket::Ptr& server)
                try {
                        Socket::Ptr client = server->Accept();
                        Utility::QueueAsyncCallback(boost::bind(&ApiListener::NewClientHandler, this, client, RoleServer));
-               } catch (std::exception&) {
+               } catch (const std::exception&) {
                        Log(LogCritical, "ApiListener", "Cannot accept new connection.");
                }
        }
@@ -268,7 +268,7 @@ void ApiListener::NewClientHandler(const Socket::Ptr& client, ConnectionRole rol
                ObjectLock olock(this);
                try {
                        tlsStream = make_shared<TlsStream>(client, role, m_SSLContext);
-               } catch (std::exception&) {
+               } catch (const std::exception&) {
                        Log(LogCritical, "ApiListener", "Cannot create tls stream from client connection.");
                        return;
                }
@@ -276,7 +276,7 @@ void ApiListener::NewClientHandler(const Socket::Ptr& client, ConnectionRole rol
 
        try {
                tlsStream->Handshake();
-       } catch (std::exception) {
+       } catch (const std::exception&) {
                Log(LogCritical, "ApiListener", "Client TLS handshake failed.");
                return;
        }
@@ -286,7 +286,7 @@ void ApiListener::NewClientHandler(const Socket::Ptr& client, ConnectionRole rol
 
        try {
                identity = GetCertificateCN(cert);
-       } catch (std::exception&) {
+       } catch (const std::exception&) {
                Log(LogCritical, "ApiListener", "Cannot get certificate common name from cert path: '" + GetCertPath() + "'.");
                return;
        }