Exception 为什么Xamarin解决方案中不显示来自异常的自定义异常消息?

Exception 为什么Xamarin解决方案中不显示来自异常的自定义异常消息?,exception,xamarin,visual-studio-2017,Exception,Xamarin,Visual Studio 2017,我已经了解了Xamarin跨平台移动开发的这个示例: 我在代码中复制了两次API密钥时出错: using System; using System.Threading.Tasks; namespace XWeatherApp { public class Core { public static async Task<Weather> GetWeather(string zipCode) { //Sign u

我已经了解了Xamarin跨平台移动开发的这个示例:

我在代码中复制了两次API密钥时出错:

using System;
using System.Threading.Tasks;

namespace XWeatherApp
{
    public class Core
    {
        public static async Task<Weather> GetWeather(string zipCode)
        {
            //Sign up for a free API key at http://openweathermap.org/appid  
            string key = "40aabb59f41e9e88db7be4bab11f49f8";
            string queryString = "http://api.openweathermap.org/data/2.5/weather?zip="
                + zipCode + ",us&appid=" + key + "&units=imperial";

            //Make sure developers running this sample replaced the API key
            if (key == "40aabb59f41e9e88db7be4bab11f49f8")
            {
                throw new ArgumentException("You must obtain an API key from openweathermap.org/appid and save it in the 'key' variable.");
            }

            dynamic results = await DataService.getDataFromService(queryString).ConfigureAwait(true);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title = (string)results["name"];
                weather.Temperature = (string)results["main"]["temp"] + " F";
                weather.Wind = (string)results["wind"]["speed"] + " mph";
                weather.Humidity = (string)results["main"]["humidity"] + " %";
                weather.Visibility = (string)results["weather"][0]["main"];

                DateTime time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset = sunset.ToString() + " UTC";
                return weather;
            }
            else
            {
                return null;
            }
        }
    }
}
使用系统;
使用System.Threading.Tasks;
命名空间XWeatherApp
{
公共类核心
{
公共静态异步任务GetWeather(字符串zipCode)
{
//注册一个免费的API密钥http://openweathermap.org/appid  
string key=“40aabb59f41e9e88db7be4bab11f49f8”;
字符串查询字符串=”http://api.openweathermap.org/data/2.5/weather?zip="
+zipCode+”,us&appid=“+key+”&单位=英制”;
//确保运行此示例的开发人员替换了API密钥
如果(键==“40aabb59f41e9e88db7be4bab11f49f8”)
{
抛出新ArgumentException(“您必须从openweathermap.org/appid获取API密钥,并将其保存在'key'变量中。”);
}
动态结果=await DataService.getDataFromService(queryString).ConfigureAwait(true);
如果(结果[“天气”]!=null)
{
天气=新天气;
weather.Title=(字符串)结果[“name”];
weather.Temperature=(字符串)结果[“main”][“temp”]+“F”;
weather.Wind=(字符串)结果[“风”][“速度”]+“英里/小时”;
weather.湿度=(字符串)结果[“main”][“湿度”]+“%”;
weather.Visibility=(字符串)结果[“weather”][0][“main”];
日期时间=新系统的日期时间(1970,1,1,0,0,0);
DateTime sunrise=time.AddSeconds((双精度)结果[“sys”][“sunrise”]);
DateTime日落=time.AddSeconds((双精度)结果[“sys”][“日落”]);
weather.Sunrise=Sunrise.ToString()+“UTC”;
weather.Sunset=Sunset.ToString()+“UTC”;
回归天气;
}
其他的
{
返回null;
}
}
}
}
具体来说,在两条注释后面的行中

我将该应用程序部署到一部物理Android手机上。很明显,我遇到了一个异常(在查找失败代码的几分钟后,这个异常就不那么明显了)

该异常未显示在输出窗口中(在Visual Studio 2017中)。我只是在屏幕上看到这条信息:


为什么不删除异常的自定义消息(即,您必须从openweathermap.org/appid获取API密钥并将其保存在“key”变量中。)。

您是否尝试过使用try/catch

差不多

try{
    await GetWeather(string zipCode);
}
catch(Exception ex) {
    // here you should have your exception
}

除非您在catch部分尝试/catch并打印异常,否则异常消息将显示在debug output窗口中。