结束函数不会在所有代码路径上返回值

时间:2015-04-06 21:06:23

标签: function visual-studio-2012

我在“结束功能”下面有一个绿色的波浪形,它提示我说:“你错过了一个回复声明吗?”当我确实有一个回复声明。这就是我所拥有的:

Private Function TaxCalcFunc(ByVal propVal As Decimal, ByVal perc As Decimal, ByVal rate As Decimal) As Decimal
    Dim AssessedValue As Decimal
    Dim Tax As Decimal
    Try
        AssessedValue = propVal * perc
        Tax = AssessedValue / 100 * rate
        Return Tax
        If rate > 1 Or perc > 1 Then
            Throw New Exception("Tax Greater Than Value. Did you use the decimal Point?")
        End If

    Catch ex As Exception
        MessageBox.Show(0)

    End Try
    'I was unable to get rid of the green squiggle for some reason, says I am missing a return statement
End Function

1 个答案:

答案 0 :(得分:0)

return语句内部或之后没有Catch语句,因此如果在Return Tax代码之前抛出异常,那么您的函数确实不会返回值。