我正在使用Visual Studio 2013中最新版本的Xamarin Android . 当我调试我的代码时,catch块没有捕获任何抛出的异常 . 它正在工作,然后它似乎停止了 . 我不知道发生了什么 . 以下代码是问题的实际实例的简化表示 .
// private Context _context; set by class constructor and is valid
// private Version _storedVersions
try
{
// This line works as expected.
ISharedPreferences sharedPrefs = _context.GetSharedPreferences("shared.prefs.file", FileCreationMode.Private);
// This line also works as expected. GetString() returns the default 'null'
// because the sharePrefs file was just created and is empty.
string versions = sharedPrefs.GetString("Versions", null)
// This line throws a System.ArgumentNullException because 'versions' is null.
// This is also to be expected.
_storedVersions = JsonConvert.DeserializeObject<Versions>(versions);
// The problem is that 'catch' does not catch the exception.
// The debugger breaks on the JsonConvert line above.
// RespondAccordingly() does not get called.
}
catch
{
// Never called
RespondAccordingly();
}
有没有人见过这个?更好的是,有谁知道如何解决它?我死在水里,直到我能解决这个问题 .
UPDATE: The non-debug version of the app loads and runs fine on the device. The debug version also runs just fine on the device as long as the debugger is not attached.