vb net无法捕获'n。 def'使用Try Catch

时间:2015-07-31 08:09:19

标签: vb.net

我正在使用vb .net(Visual Studio 2013)并且必须在快速循环(0.000001 s)中执行一些数学运算:我得到了'n。 def'结果。我想找出错误发生的地方,以便能够解决它;我尝试过使用Try ... Catch但没有成功。我还能尝试什么? 谢谢你的帮助

这里有一些代码作为帮助:

' ---------------------------------------------------------------------------------------------------
'                                   Lateral Segment Area Case 4
' ---------------------------------------------------------------------------------------------------
''' <summary>
''' LateralSegmentArea4: lateral segment area type 4
''' </summary>
''' <param name="y">crcle radius</param>
''' <param name="xm">radius of screw circle</param>
''' <param name="na">number of screws</param>
''' <param name="Fa">area calculated</param>
''' <param name="Test">Test: true|false</param>
''' <param name="destination">logging path</param>
''' <returns>status</returns>
''' <remarks></remarks>
Public Shared Function LateralSegmentArea4(y As Double,
                                          xm As Double,
                                          na As Double,
                                          ByRef Fa As Double,
                                          Test As Boolean,
                                          destination As String) As Boolean

    Dim ret As Boolean = True
    Dim status As Boolean = True
    Dim logstr As String = String.Empty
    Dim psi As Double = 0
    Dim ym As Double = 0
    Dim found As Boolean = False
    Dim alpha1 As Double = 0
    Dim alpha2 As Double = 0
    Dim phi As Double = 0
    Dim x1 As Double = 0
    Dim y1 As Double = 0
    Dim x2 As Double = 0
    Dim y2 As Double = 0
    Dim Aseg As Double = 0
    Dim result As Double = 0

    Try
        ' psi
        psi = 360 / na

        ' crosspoints x1, x2
        ret = General.CrosspointsCircleStraightline(xm, ym, y, psi / 2, x2, x1, found, destination)
        If found = True Then
            y1 = Math.Tan(psi / 2 * Math.PI / 180) * x1
            y2 = Math.Tan(psi / 2 * Math.PI / 180) * x2

            ' phi
            alpha1 = Math.Asin(y1 / y)
            If x2 >= xm Then
                alpha2 = Math.Asin(y2 / y)
            Else
                alpha2 = Math.PI - Math.Asin(y2 / y)
            End If
            phi = Math.PI - alpha1 - alpha2

            ' segment area
            Aseg = Math.Pow(y, 2) / 2 * (phi - Math.Sin(phi))

            ' lateral area
            result = 2 * Aseg
            Fa = result

            If Test Then
                Logging.WriteLogFile("", False, destination)
                Logging.WriteLogFile("LateralSegmentArea4", False, destination)
                Logging.WriteLogFile("x1: " & x1, False, destination)
                Logging.WriteLogFile("y1: " & y1, False, destination)
                Logging.WriteLogFile("x2: " & x2, False, destination)
                Logging.WriteLogFile("alpha1: " & alpha1, False, destination)
                Logging.WriteLogFile("alpha2: " & alpha2, False, destination)
                Logging.WriteLogFile("phi: " & phi, False, destination)
                Logging.WriteLogFile("Aseg: " & Aseg, False, destination)
            End If
        End If
    Catch ex As Exception
        logstr = "Error while getting lateral segment area 4 (" & ex.ToString & ")"
        Logging.WriteLogFile(logstr, True, destination)
        status = False
    End Try

    If status = True Then status = ret
    Return status
End Function

'---------------------------------------------- -------------------------------------------------- ---     'Crosspoints Circle直线     '------------------------------------------------- --------------------------------------------------     “””     '''CrosspointsCircleStraightline:确定圆和直线的交叉点     “””     '''s-circle of srew circle     '''s-circle of srew circle     '''圆半径     '''直线的角度     '''x1-交叉点     '''x2-交叉点     '''交叉点发现:真实假     '''记录路径     ''' 状态     “””     公共共享功能CrosspointsCircleStraightline(xm As Double,                                                                  嗯双重,                                                                  r双,                                                                  phi As Double,                                                                  ByRef x1 As Double,                                                                  ByRef x2 As Double,                                                                  ByRef发现为布尔值,                                                                  destination As String)As Boolean

    Dim ret As Boolean = True
    Dim status As Boolean = True
    Dim logstr As String = String.Empty
    Dim a As Double = 0
    Dim part0 As Double = 0
    Dim part1 As Double = 0
    Dim part2 As Double = 0
    Dim part3 As Double = 0
    Dim part4 As Double = 0
    Dim angle As Double = 0

    Try
        found = False
        angle = phi * Math.PI / 180
        a = Math.Tan(angle)

        ' part0 = 2*xm + 2*a*ym
        part0 = 2 * xm + 2 * a * ym

        ' part1 = (2*xm + 2*a*ym)^2
        part1 = Math.Pow((2 * xm + 2 * a * ym), 2)

        ' part2 = 4*(1+a^2)*(xm^2+ym^2-r^2)
        part2 = 4 * (1 + Math.Pow(a, 2)) * (Math.Pow(xm, 2) + Math.Pow(ym, 2) - Math.Pow(r, 2))

        ' part3 = 2*(1+a^2)
        part3 = 2 * (1 + Math.Pow(a, 2))

        'part4 = (2*xm + 2*a*ym)^2 - 4*(1+a^2)*(xm^2+ym^2-r^2)
        part4 = part1 - part2
        If part4 < 0 Then
            Threading.Thread.Sleep(100)
            ' repeat
            part4 = part1 - part2
        End If

        ' crosspoint found?
        If part4 > 0 Then
            found = True
            x1 = (part0 + Math.Sqrt(part4)) / part3
            x2 = (part0 - Math.Sqrt(part4)) / part3
        Else
            found = False
        End If
    Catch ex As Exception
        logstr = "Error while finding cross points (" & ex.ToString & ")"
        Logging.WriteLogFile(logstr, True, destination)
        status = False
    End Try

    If status = True Then status = ret
    Return status
End Function

0 个答案:

没有答案