在下面的方法中,当我们有案例'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
答案 0 :(得分: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