【问题标题】:Windows phone Argument ExceptionWindows phone 参数异常
【发布时间】:2013-12-16 17:27:08
【问题描述】:

我收到错误,因为“System.Windows.ni.dll 中发生了 'System.ArgumentException' 类型的异常,但未在用户代码中处理”

    void Touch_FrameReported(object sender, TouchFrameEventArgs e)
    {
        int pointsNumber = e.GetTouchPoints(img1).Count; \\ I got the Exception in this Line
        TouchPointCollection pointCollection = e.GetTouchPoints(img1);

        for (int i = 0; i < pointsNumber; i++)
        {
            if (pointCollection[i].Action == TouchAction.Down)
            {
                preXArray[i] = pointCollection[i].Position.X;
                preYArray[i] = pointCollection[i].Position.Y;
            }
            if (pointCollection[i].Action == TouchAction.Move)
            {
                line = new Line();

                line.X1 = preXArray[i];
                line.Y1 = preYArray[i];
                line.X2 = pointCollection[i].Position.X;
                line.Y2 = pointCollection[i].Position.Y;

                line.Stroke = new SolidColorBrush(Colors.White);

                line.StrokeStartLineCap = PenLineCap.Round;
                line.StrokeEndLineCap = PenLineCap.Round;
                line.StrokeThickness = 20;
                img1.Children.Add(line);

                preXArray[i] = pointCollection[i].Position.X;
                preYArray[i] = pointCollection[i].Position.Y;
            }
        }
    }

如何在 Windows Phone 8 中处理此异常

【问题讨论】:

    标签: windows-phone-8


    【解决方案1】:

    你需要一个像这样的 catch 块的 try catch...

     try { ... }
       catch(System.ArgumentNullException ane) { ... }
       catch(System.NotSupportedException nse) { ... }
       catch(System.IO.PathTooLongException ple) { ... }
       catch(System.IO.SecurityException se) { ... }
       catch(System.ArgumentException ae) { ... }
    

    确保您的“System.ArgumentException”是您最后的收获。如果需要,请使用上面的 4,您可能不需要路径处理程序...

    【讨论】:

    • 我已经使用 catch(System.ArgumentException ae) { throw(ae)} 但应用程序变得非常慢。怎么办
    • 专注于确保您的 'img1' 变量永远不会为空,并将条件放入 GetTouchPoints() 以始终返回计数。然后,您将永远不必担心捕获 sys 异常..
    猜你喜欢
    • 2013-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-24
    相关资源
    最近更新 更多