Exception handling
Updated at:2025-11-03
BOS exception prompts are available in the following two ways:
| Exception type | Description |
|---|---|
| BceClientException | Client exception |
| BceServiceException | Server exception |
Users can attempt to capture exceptions triggered by specific events.
-
Example code
Java1String objectKey = "testObjectToFile"; 2bosclient.putObject(<BucketName>, <ObjectKey>, <DataFile>); 3File file = new File("test"); 4try { 5 bosclient.getObject(this.bucketName, objectKey, file); 6 } catch (BceServiceException bce){ 7 System.out.println("Error ErrorCode: " + e.getErrorCode()); 8 System.out.println("Error RequestId: " + e.getRequestId()); 9 System.out.println("Error StatusCode: " + e.getStatusCode()); 10 System.out.println("Error ErrorType: " + e.getErrorType()); 11 System.out.println("Error Message: " + e.getMessage()); 12 } catch ( BceClientException bce){ 13 System.out.println( bce.getMessage()); 14 } finally { 15 file.delete(); 16 }
