百度智能云

All Product Document

          Object Storage

          Exception Handling

          Client Exception

          Client exception indicates an exception encountered when the client attempts to send a request to the BOS and transmits data. For example, when the network connection is unavailable, the client operation returns non-zero when the request is sent; and returns non-zero when an IO exception occurs while a file is uploaded.

          The client returns non-zero when executing put_object, delete_bucket and other operations. See bcesdk/common/common.h for specific error code information returned. You can also call the stringfy_ret_code function in bcesdk/util/util.h to convert the returned error code into a string for printing.

          int ret = client.upload_file("bucketName", "objectName", "fileName");
          if (ret != 0) {
              std::cout << "client error occurs: " << stringfy_ret_code(ret) << std::endl;
              return ret;
          }
          return RET_OK;//RET_OK=0represents successful execution

          Server Exception

          When an exception occurs on the BOS server, the BOS server returns the corresponding error message to the user to locate the problem. Common server exceptions can be found in BOS Error Message Format.

          If an exception occurs on the server, the error message will be written to the response, and the exception will be handled through the response.

          int ret = client.put_object(request, &response);
          if (response.is_fail()) {
              //Status code, 0 for success, 400-599 for HTTP error code, 1000- for client error
              int status = response.status_code();
              std::string msg = response.error().message();
              printf("put object fail, [status_code = %d], [message = %s]", status, msg.c_str());
              return status;
          }
          return RET_OK;
          Previous
          File Management
          Next
          sdk Log