【问题标题】:When even "try-catch" fails with System.AggregateException当甚至“try-catch”因 System.AggregateException 而失败时
【发布时间】:2018-12-03 19:36:15
【问题描述】:

我收到上述错误:System.AggregateException: One or more errors occurred.

这里有这行代码:

    List<tblDeviceIds> installIDs = KumulosHelper.Functions.Device.GetDeviceIDsOfUser(toUser);

方法“GetDeviceIdsOfUser”如下所示:

    public static List<tblDeviceIds> GetDeviceIDsOfUser(string username)
    {
        IDictionary<string, string> myDict = new Dictionary<string, string>();
        myDict.Add("username", username);
        return KumulosGeneral.getTblDeviceIds("getDeviceIDsOfUser", myDict);
    }

所以,真的没有什么花哨的事情发生。

有时,但仅限于某些用户出现上述错误。因此,即使用户是“null”,而他从来不是,列表也不会返回任何内容。但相反,它崩溃了。这本身就是我不太明白的事情,所以我所做的是:

        List<tblDeviceIds> installIDs = null;

        try
        {
            installIDs = KumulosHelper.Functions.Device.GetDeviceIDsOfUser(toUser);
        }
        catch
        {
            installIDs = null;
        }

这将是一个子弹证明的解决方法,但是:它进入 try,它崩溃,它永远不会进入 catch,它已经死了。 有人愿意解释一下吗?

谢谢!

哦,也许这与在另一个线程上执行此操作有关?这是调用所有这些的函数:

        await Task.Run(() =>
        {
            Intermediate.SendMessageToUser(toUsername, temp);
        });

如您所见,它位于异步任务中……但这应该不是问题,对吧?

【问题讨论】:

    标签: android android-asynctask xamarin.android


    【解决方案1】:

    您收到 AggregateException 的原因是异常源自任务内部(可能在单独的线程上运行)。要确定原因,请查看 InnerException(s)。

    关于未捕获的问题,我的建议是:确保使用的是最新代码。添加跟踪而不是依赖断点。并查看内部异常是否从另一个线程抛出(GetDeviceIDsOfUser 是否也使用异步?)

    另请参阅:Why is .NET exception not caught by try/catch block?

    【讨论】:

      猜你喜欢
      • 2021-04-22
      • 2019-02-27
      • 1970-01-01
      • 2010-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-16
      • 1970-01-01
      相关资源
      最近更新 更多