异常处理
更新时间:2022-01-19
BOS异常提示有如下两种方式:
异常方法 | 说明 |
---|---|
BceClientException | 客户端异常 |
BceServiceException | 服务器异常 |
用户可以使用try获取某个事件所产生的异常。
-
示例代码
String objectKey = "testObjectToFile"; bosclient.putObject(<BucketName>, <ObjectKey>, <DataFile>); File file = new File("test"); try { bosclient.getObject(this.bucketName, objectKey, file); } catch (BceServiceException bce){ System.out.println("Error ErrorCode: " + e.getErrorCode()); System.out.println("Error RequestId: " + e.getRequestId()); System.out.println("Error StatusCode: " + e.getStatusCode()); System.out.println("Error ErrorType: " + e.getErrorType()); System.out.println("Error Message: " + e.getMessage()); } catch ( BceClientException bce){ System.out.println( bce.getMessage()); } finally { file.delete(); }