Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Handling errors in the AWS SDK for C++

Focus mode
Handling errors in the AWS SDK for C++ - AWS SDK for C++

The AWS SDK for C++ does not use exceptions; however, you can use exceptions in your code. Every service client returns an outcome object that includes the result and an error code.

Example of handling error conditions

bool CreateTableAndWaitForItToBeActive() { CreateTableRequest createTableRequest; AttributeDefinition hashKey; hashKey.SetAttributeName(HASH_KEY_NAME); hashKey.SetAttributeType(ScalarAttributeType::S); createTableRequest.AddAttributeDefinitions(hashKey); KeySchemaElement hashKeySchemaElement; hashKeySchemaElement.WithAttributeName(HASH_KEY_NAME).WithKeyType(KeyType::HASH); createTableRequest.AddKeySchema(hashKeySchemaElement); ProvisionedThroughput provisionedThroughput; provisionedThroughput.SetReadCapacityUnits(readCap); provisionedThroughput.SetWriteCapacityUnits(writeCap); createTableRequest.WithProvisionedThroughput(provisionedThroughput); createTableRequest.WithTableName(tableName); CreateTableOutcome createTableOutcome = dynamoDbClient->CreateTable(createTableRequest); if (createTableOutcome.IsSuccess()) { DescribeTableRequest describeTableRequest; describeTableRequest.SetTableName(tableName); bool shouldContinue = true; DescribeTableOutcome outcome = dynamoDbClient->DescribeTable(describeTableRequest); while (shouldContinue) { if (outcome.GetResult().GetTable().GetTableStatus() == TableStatus::ACTIVE) { break; } else { std::this_thread::sleep_for(std::chrono::seconds(1)); } } return true; } else if(createTableOutcome.GetError().GetErrorType() == DynamoDBErrors::RESOURCE_IN_USE) { return true; } return false; }
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.