7. 错误处理

7.1. 异常处理

  • 在调用相关的方法之后,都有一个返回值,而其有一个判断是否执行成功的方法:IsSuccess(), 如果执行成功,那么返回true,反之false
  • 如果失败,那么可以通过下面代码打印出错信息:
std::cout << "DeleteObject error: " << delete_object_outcome.GetError().GetExceptionName() << " " << delete_object_outcome.GetError().GetMessage() << std::endl;

7.2. 示例代码

Aws::S3::Model::DeleteObjectRequest object_request;
object_request.WithBucket(bucketName).WithKey(objectName);
auto delete_object_outcome = s3Client.DeleteObject(object_request);
if (delete_object_outcome.IsSuccess())
{
    std::cout << "Done!" << std::endl;
}
else
{
    std::cout << "DeleteObject error: " <<
    delete_object_outcome.GetError().GetExceptionName() << " " <<
    delete_object_outcome.GetError().GetMessage() << std::endl;
}