Try/Catch not working for WP8 C# .NET with Azure Mobile Services

感情迁移 提交于 2020-01-25 12:58:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!