From bbbaa06b5c93b4ff5059e31660b86462194bb2d5 Mon Sep 17 00:00:00 2001 From: Rick Winter Date: Thu, 16 Jul 2020 15:44:34 -0700 Subject: [PATCH] Exception objects should be thrown and not the pointer to the exception object. (#322) Exception objects should be thrown and not the pointer to the exception object. https://azure.github.io/azure-sdk/cpp_design.html#c-exceptions The pattern for the catch expects a reference to the exception and not the pointer. Example: try{ throw Myxception(); } catch (MyException const& e) { //process } --- sdk/core/azure-core/src/credentials/credentials.cpp | 4 ++-- sdk/core/azure-core/src/http/curl/curl.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sdk/core/azure-core/src/credentials/credentials.cpp b/sdk/core/azure-core/src/credentials/credentials.cpp index 8de5a0c1e..0d47996ef 100644 --- a/sdk/core/azure-core/src/credentials/credentials.cpp +++ b/sdk/core/azure-core/src/credentials/credentials.cpp @@ -194,10 +194,10 @@ AccessToken ClientSecretCredential::GetToken( } catch (std::exception const& e) { - throw new AuthenticationException(e.what()); + throw AuthenticationException(e.what()); } catch (...) { - throw new AuthenticationException("unknown error"); + throw AuthenticationException("unknown error"); } } diff --git a/sdk/core/azure-core/src/http/curl/curl.cpp b/sdk/core/azure-core/src/http/curl/curl.cpp index f6f83ab2c..1d8b56be7 100644 --- a/sdk/core/azure-core/src/http/curl/curl.cpp +++ b/sdk/core/azure-core/src/http/curl/curl.cpp @@ -21,12 +21,12 @@ std::unique_ptr CurlTransport::Send(Context& context, Request& request { case CURLE_COULDNT_RESOLVE_HOST: { - throw new Azure::Core::Http::CouldNotResolveHostException( + throw Azure::Core::Http::CouldNotResolveHostException( "Could not resolve host " + request.GetHost()); } default: { - throw new Azure::Core::Http::TransportException( + throw Azure::Core::Http::TransportException( "Error while sending request. " + std::string(curl_easy_strerror(performing))); } } @@ -524,15 +524,15 @@ int64_t CurlSession::ReadSocketToBuffer(uint8_t* buffer, int64_t bufferSize) if (!WaitForSocketReady(this->m_curlSocket, 0, 60000L)) { // TODO: Change this to somehing more relevant - throw new Azure::Core::Http::TransportException( + throw Azure::Core::Http::TransportException( "Timeout waiting to read from Network socket"); } break; case CURLE_OK: break; default: - // Error code while reading from socket - throw new Azure::Core::Http::TransportException("Error while reading from network socket"); + // Error reading from socket + throw Azure::Core::Http::TransportException("Error while reading from network socket"); } } return readBytes;