0

在下面的方法中,当我们有 case 'Else' 时,它应该抛出一个异常,但由于某种原因,这个异常根本没有被记录。您能指出下面编写的代码中的任何问题吗?我们可以在 Select 和 Case 语句中捕获异常吗?

  Private Sub Country(ByVal Row As Input0Buffer)
        mColumnName = "BORR1_MAILCOUNTRY_CD"
        Dim errmsg As String = String.Empty

        If Row.outBORR1MAILTOADDRSUBPROP = "Y" Then
            ' Property country is a manual-entry field and can have junk
            Dim outCountry As String = String.Empty
            Dim inCountry As String = GetSafeParsedString(Row.inPROPCOUNTRY)
            inCountry = inCountry.Replace(".", String.Empty)
            inCountry = inCountry.Replace(" ", String.Empty)
            inCountry = inCountry.ToUpper()

            Select Case GetSafeParsedString(inCountry)
                Case "USA"
                    outCountry = "US"
                Case "US"
                    outCountry = "US"
                Case "UNITED STATES"
                    outCountry = "US"
                Case "MEXICO"
                    outCountry = "MX"
                Case "MX"
                    outCountry = "MX"
                Case "CANADA"
                    outCountry = "CA"
                Case "CA"
                    outCountry = "CA"
                Case "CAN"
                    outCountry = "CA"
                Case String.Empty
                    outCountry = String.Empty
                Case Else
                    errmsg = String.Format("Can not map country.MailToSubProp is 'Y' but property country was input as  {0}", inCountry)
                    Throw New Exception(errmsg)
                    Return
            End Select

        END IF 
    End Sub
4

1 回答 1

0

我认为您不需要捕获异常,否则无需首先抛出异常

 Case Else
        errmsg = String.Format("Can not map country.MailToSubProp is 'Y' but property country was input as  {0}", inCountry)
     Try
        Throw New Exception(errmsg)
     Catch ex As Exception
         'Log exception here
     End Catch
 End Select
于 2013-01-02T19:40:20.310 回答