我试图用下面的代码捕获smtpclass的内部异常,但是它给出了另一个错误,说明没有定义innerexception
Try
mail.To.Add(lstRecipients(i))
Try
SetStatus("Sending:-" & lstRecipients(i))
smtp.Send(mail)
lSent += 1
bwrkMain.ReportProgress(i + 1)
SetStatus("Sent:-" & lstRecipients(i))
lSent += 1
Catch ex As SmtpFailedRecipientsException
bwrkMain.ReportProgress(i + 1)
SetStatus("Error:-" & lstRecipients(i) & " - " &
ex.InnerException.Message)
End Try
Catch ex As Exception
SetStatus("Error:-" & lstRecipients(i) & " - " & ex.Message)
End Try
答案 0 :(得分:2)
未定义InnerException,请查看Exceptions within Exceptions部分
答案 1 :(得分:1)
确保在尝试使用之前检查您的InnerException是否为Nothing:
If Not(ex.InnerException Is Nothing) Then
SetStatus("Error:-" & lstRecipients(i) & " - " &
ex.InnerException.Message)
End If