smtpclass vb.net2008中的catch ex.innerexception

smtpclass vb.net2008中的catch ex.innerexception,.net,vb.net,winforms,exception-handling,smtpclient,.net,Vb.net,Winforms,Exception Handling,Smtpclient,我试图用下面的代码捕获smtpclass的内部异常,但它给出了另一个错误,表示未定义innerexception Try mail.To.Add(lstRecipients(i)) Try SetStatus("Sending:-" & lstRecipients(i)) smtp.Send(mail) lSent += 1 bwrkMain.ReportProgress(i + 1) Se

我试图用下面的代码捕获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

InnerException未定义,请查看部分

InnerException未定义,请查看部分

在尝试使用它之前,请确保检查InnerException是否为空:

If Not(ex.InnerException Is Nothing) Then
     SetStatus("Error:-" & lstRecipients(i) & " - " &
            ex.InnerException.Message)
End If

在尝试使用InnerException之前,请确保检查它是否为Nothing:

If Not(ex.InnerException Is Nothing) Then
     SetStatus("Error:-" & lstRecipients(i) & " - " &
            ex.InnerException.Message)
End If

wehn i send mail i get error
发送邮件失败
。是否可以获取邮件未发送的实际原因,例如网络错误、smtp服务器错误或ivalid smtp密码验证etc@Smith我不知道如何获得更多关于为什么发送电子邮件的信息。好机会再发一个问题。wehn i send mail i get error
发送邮件失败
。是否可以获取邮件未发送的实际原因,例如网络错误、smtp服务器错误或ivalid smtp密码验证etc@Smith我不知道如何获得更多关于为什么发送电子邮件的信息。不过,这是一个发布另一个问题的好机会。