views:

22

answers:

1

Hi

Here's my problem I have some code and I'm using it to send an e-mail with the last error details but all I want is the (Inner)Exception Message to be displayed in the email with the URL

Here's my code

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)

' Get current exception 
    Dim err As System.Exception = Server.GetLastError

    Dim ErrorDetails As String = err.Exception.Message

    Dim ErrorURL As String = Request.Url.ToString()

    ' Send notification e-mail
    Dim Email As MailMessage = _
        New MailMessage("[email protected]", [email protected]")
    Email.IsBodyHtml = False
    Email.Subject = "WEB SITE ERROR"
    Email.Body = ErrorDetails & vbcrlf & vbcrlf & ErrorURL
    Email.Priority = MailPriority.High
    Dim sc As SmtpClient = New SmtpClient("localhost")
    sc.Send(Email)

End Sub

Any help would be much appreciated

Thanks

Jamie

+2  A: 

Use err.ToString() - this gives you the full strack trace and inner exceptions.

If you really only want the inner exception error message, use err.InnerException.Message

ck
The err.InnerException.Message doesn't seem to show anything in the email is it because it's null? And why would it be null from an error?
Jamie Taylor
@Jamie Taylor - possibly becuase you are catching a primary exception and there _is_ no inner exception. That's why using `err.ToString()` is better in order to get the full details.
Oded
I understand now - if there is an innerexception then it does pass it - i'm struggling to understand what an innereception is though?
Jamie Taylor
An Inner Exception is just another exception that happened further into the Stack. For example, a `NullReferenceException` could be thrown, caught, and then a new custom `ApplicationException` be thrown that includes the `NullReferenceException` as its InnerException, allowing you to see the original exception, but then also any further context that has been added to the `ApplicationException`
ck