I am working with the latest version of Xamarin Android in Visual Studio 2013. When I debug my code, the catch blocks are not catching any thrown exceptions. It was working, and then it just seemed to stop. I have no idea what happened. The following code is a simplified representation of an actual instance of the problem.
// 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();
}
Has anyone ever seen this? Better yet, does anyone know how to fix it? I am dead in the water until I can get this fixed.
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.