问题
I'm playing around with this block of code:
try
{
mscvUser = imstUser
.Where(User => User.Id == intId)
.Take(1000)
.ToCollectionView();
}
catch(MobileServiceInvalidOperationException f){
MessageBox.Show(f.ToString());
}
It works fine normally, but I've been deliberately disconnecting my Internet for testing purposes, and I keep hitting MobileServiceInvalidOperationException, but it won't catch it in that block; it throws it back to App.xaml.cs, breaks, and shuts down the app.
回答1:
I think you are not using the newest version of Azure Mobile Services. The SDK was recently updated to version 1.0: http://nuget.org/packages/WindowsAzure.MobileServices/
I checked with this version and the exception is catched correctly.
In the newest version, "ToCollectionView" was replaced and you'd now have to use
try
{
mscvUser = await imstUser
.Where(User => User.Id == intId)
.Take(1000)
.ToCollectionAsync();
}
catch(MobileServiceInvalidOperationException f){
MessageBox.Show(f.ToString());
}
Hope this helps
edit: Here from the changelog:
MobileServiceTable.ToCollectionView() is now ToCollection(): the collection view implementation had some bugs, and it has been rewritten.
As you can read here
来源:https://stackoverflow.com/questions/17232794/try-catch-not-working-for-wp8-c-sharp-net-with-azure-mobile-services