Exception handling
Updated at:2025-11-03
BOS exception prompts are available in the following four ways:
| Exception type | Description |
|---|---|
| BceBaseException | Collection of exceptions |
| BceClientException | Client exception |
| BceServerException | Server exception |
| InvalidArgumentException | System-built-in exceptions, parameter errors |
Users can use try to obtain the exception generated by a certain event:
PHP
1try {
2 $client->deleteObject($bucketName, $objectKey);
3} catch (\BaiduBce\Exception\BceBaseException $e) {
4 print $e->getMessage();
5 if (strcmp(get_class($e), "BaiduBce\Exception\BceClientException") == 0) {
6 print "Catch a client exception";
7 }
8 if (strcmp(get_class($e), "BaiduBce\Exception\BceServiceException") == 0) {
9 print "Catch a server exception";
10 }
11 if (strcmp(get_class($e), "BaiduBce\Exception\BceBaseException") == 0) {
12 print "Catch a base exception";
13 }
14 if (strcmp(get_class($e), "BaiduBce\Exception\InvalidArgumentException") == 0) {
15 print "Catch a invalid argument exception";
16 }
17};
Client exception
A client exception occurs when the client encounters issues while sending requests or transmitting data to BOS. For example, ClientException is thrown for network failures or I/O errors during file uploads.
Server exception
A server exception is generated when BOS server-side errors occur. The service returns detailed error messages to assist troubleshooting. For common server exceptions, refer to [BOS Error Message Format](BOS/API Reference/Error code.md)
