This article introduces exception handling when using the TOS SDK.
TOS Server Errors
SDK Custom Exceptions/Errors
Client Exceptions/Errors - TosClientError
TosClientError occurs due to client input errors, connection timeouts, or special operations such as client cancellation of breakpoint resume uploads. For example, when creating a bucket using create_bucket, an exception is thrown if the bucket name exceeds 63 characters.
Server Exceptions/Errors - TosServerError
Send requests to the TOS server using the TOS Python SDK interface. The response includes HTTP-compliant status codes and business error codes that indicate the current request's response status.
Example of exception/error handling
The following code demonstrates exception handling when downloading a nonexistent object. If a TosServerError occurs, it prints the HTTP request status code and request ID; if a TosClientError occurs, it prints the error message.