使用 Dropbox .NET 庫獲取不存在路徑的後設資料時處理錯誤
此示例使用 Dropbox .NET 庫嘗試獲取特定路徑上的專案的後設資料,並檢查 NotFound
錯誤:
try {
var metadata = await this.client.Files.GetMetadataAsync("/non-existant path");
Console.WriteLine(metadata.Name);
} catch (Dropbox.Api.ApiException<Dropbox.Api.Files.GetMetadataError> e) {
if (e.ErrorResponse.IsPath) {
var pathError = e.ErrorResponse.AsPath.Value;
if (pathError.IsNotFound) {
Console.WriteLine ("File or folder not found.");
} else {
Console.WriteLine (pathError);
}
} else {
Console.WriteLine (e.ErrorResponse);
}
}