0

以下のメソッドでは、ケース「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 に答える