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  }
This commit is contained in:
Rick Winter 2020-07-16 15:44:34 -07:00 committed by GitHub
parent b69080bc48
commit bbbaa06b5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -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");
}
}

View File

@ -21,12 +21,12 @@ std::unique_ptr<Response> 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;