[英]Flurl exception not being caught
我不明白為什么,但是我收到了Flurl Exception,而try / catch塊沒有捕獲這些異常。 關於為什么發生的任何想法?
這是代碼:
try
{
var x = await Utils.Sales.GetUrl()
.PostJsonAsync(new Sale
{
MerchantId = Constants.Sandbox.MerchantId
})
.ReceiveJson<Sale>();
var b = x;
}
catch (FlurlHttpTimeoutException)
{
//LogError("Timed out!"); //todo:
}
catch (FlurlHttpException ex)
{
var x = ex.Message;
//todo:
//if (ex.Call.Response != null)
// LogError("Failed with response code " + call.Response.StatusCode);
//else
// LogError("Totally failed before getting a response! " + ex.Message);
}
catch (Exception ex)
{
var a = ex.Message;
}
這是輸出(我知道拋出異常的唯一原因):
也許此頁面會有所幫助https://msdn.microsoft.com/zh-cn/library/jj619227.aspx
抱歉,沒有英文版本,您可以嘗試用Google翻譯。
捕獲異常類型或等待代碼有點不對勁。
嘗試這種方式捕獲您的異常:
try
{
await t1;
}
catch (AggregateException ex)
{
var innerEx = ex.InnerExceptions[0];
if (innerEx is NotSupportedException)
{
...
}
else if (innerEx is NotImplementedException)
{
...
}
else
{
...
}
}
```
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.