edit-icon download-icon

Handle errors

Last Updated: Mar 21, 2018

Alibaba Cloud C# SDK returns corresponding exceptions when an error occurs on the service side or the SDK side. These exceptions contain detailed error information, including the error code (ErrCode) and error message (ErrMsg).

  • ServerException is the exception returned by the corresponding Alibaba Cloud service.
  • ClientException is the exception returned by the Alibaba Cloud Java SDK.

You do not need to handle the exceptions returned by the Alibaba Cloud Java SDK. You do need to resolve the errors returned by the service.

For example, when the following error occurs, you have to modify the ID of the AccessKey according to the error message.

  1. InvalidAccessKeyId.NotFound: Specified access key is not found.

If you want to handle the client errors returned by the Alibaba Cloud C# SDK, refer to the following example to write your codes:

  1. try
  2. {
  3. CreateInstanceResponse response = client.GetAcsResponse(request);
  4. // Handle the response
  5. // ...
  6. }
  7. catch (ServerException e)
  8. {
  9. // You can add your own error handling logic here
  10. // For example, print the error message
  11. Console.WriteLine("ErrorCode=" + e.ErrorCode);
  12. Console.WriteLine("ErrorMessage=" + e.ErrorMessage);
  13. // If the problem is tricky, you can open a ticket and provide the RequestId to us
  14. Console.WriteLine("ErrorCode=" + e.RequestId);
  15. }
  16. catch (ClientException e)
  17. {
  18. // You can add your own error handling logic here
  19. // For example, print the error message
  20. Console.WriteLine("ErrorCode=" + e.ErrorCode);
  21. Console.WriteLine("ErrorMessage=" + e.ErrorMessage);
  22. }
Thank you! We've received your feedback.