您的应用已进入中断状态。此异常未落入try catch块中

时间:2019-05-10 06:43:35

标签: c#

我正在使用httpclient getasync调用。而且我要打多次。 有时它会给出这种异常,而这种异常不会属于try catch块。

    public async Task<(string exception, ObservableCollection<AddressInfo> autoCompleteInfo)> GetGooglePlacesAsync(string input)
    {
        try
        {
            using (var client = new HttpClient())
            {
                var response = await client.GetStringAsync(string.Format(GooglePlacesApi,
                GooglePlacesApiKey, WebUtility.UrlEncode(input)));

                PlacesLocationPredictions predictionList = JsonConvert.DeserializeObject<PlacesLocationPredictions>(response);

                if (predictionList.Status == "OK")
                {
                    LocationList.Clear();

                    if (predictionList.Predictions.Count > 0)
                    {
                        foreach (Prediction prediction in predictionList.Predictions)
                        {
                            LocationList.Add(new AddressInfo
                            {
                                Address = prediction.Description,
                                PlaceID = prediction.Place_Id
                            });
                        }
                    }
                }
                else
                {
                    return (predictionList.Status, null);
                }
            }
        }
        catch (Exception ex)
        {
            return (ex.Message, null);
        }
        return (null, LocationList);
    }

0 个答案:

没有答案