Exception Handling
Last Updated:2020-09-21
System Exception
There are three reminders for Media exception:
Exception method | Description |
---|---|
BceHttpClientError | Exception thrown during retry |
--last_error | Exception thrown during the final retry |
----BceClientError | Exception generated by Media's client |
----BceInvalidArgumentError | Exception generated by introduced parameter |
----BceServerError | Exception generated by Media's server |
You can use try to get exceptions generated by an event:
from baidubce.exception import BceHttpClientError
from baidubce.exception import BceServerError
from baidubce.exception import BceClientError
try:
watermark_id = "non_exist"
client.delete_watermark(watermark_id)
except BceHttpClientError as e:
print "Cannot delete the watermark: ", e.message
Returned as:
Cannot delete the watermark: Unable to execute HTTP request. Retried 0 times. A
ll trace backs:
>>>>Traceback (most recent call last):
>>>> File "C:\tools\Python27\lib\site-packages\baidubce\http\bce_http_client.py
", line 183, in send_request
>>>> if handler_function(http_response, response):
>>>> File "C:\tools\Python27\lib\site-packages\baidubce\http\handler.py", line
71, in parse_error
>>>> raise bse
>>>>BceServerError: watermark: non_exist does not exist
Or, you can use such method to access the original error information directly:
print "Cannot delete the watermark: ", e.last_error.message
Obtain:
Cannot delete the watermark: watermark: non_exist does not exist
Parameter Exception
Each call of Media Python SDK has some parameters that cannot be null with type fixed, and if such parameter returns a null value, BceClientError is returned, and if such parameter introduces type error, TypeError is returned.