调用CreateDocumentAsync()时,是否需要检查ResourceResponse 为了错误?

问题描述 投票:1回答:1

调用CreateDocumentAsync()时,是否需要检查ResourceResponse是否有错误?例如,有一个.StatusCode属性。

或者try-catch会处理所有可能的错误情况?

azure-cosmosdb
1个回答
1
投票

尝试捕捉就是这样,

try
{
    //Get a Document client
    using (client = new DocumentClient(new Uri(endpointUrl), authorizationKey))
    {
        RunDemoAsync(databaseId, CollectionId).Wait();
    }
}
catch (DocumentClientException de)
{
    Exception baseException = de.GetBaseException();
    Console.WriteLine("{0} error occurred: {1}, Message: {2}", de.StatusCode, de.Message, baseException.Message);
}
catch (Exception e)
{
    Exception baseException = e.GetBaseException();
    Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
}
finally
{
    Console.WriteLine("End of demo, press any key to exit.");
    Console.ReadKey();
}
© www.soinside.com 2019 - 2024. All rights reserved.