How to view the line the error occured on

# Thread: How to view the line the error occured on

1. Senior Member
Join Date
Dec 1969
Posts
655

## How to view the line the error occured on

Is there a way to get the line that an error occured on? I need to e-mail this information to myself when an error occurs but the ErrorMessage appears almost useless with out the line number. Any ideas?<BR><BR>Thanks,<BR><BR>Morgan

2. Member
Join Date
Dec 1969
Posts
40

## RE: How to view the line the error occured on

I don&#039;t know that this is fact, but there should be some property of the exception object that tells you that... check this page out and try some of those properties to see what you get.<BR><BR>http://samples.gotdotnet.com/quickstart/aspplus/samples/classbrowser/vb/classbrowser.aspx?assembly=mscorlib,%20Version=1.0 .3300.0,%20Culture=neutral,%20PublicKeyToken=b77a5 c561934e089&namespace=System&class=Exception

3. Senior Member
Join Date
Dec 1969
Posts
164

## Are you using Try Catch??

because if you are using Try Catch, then you can get the line number from the raised exception.<BR><BR>Try<BR> &#039;some code that might fail<BR>Catch ex as Exception<BR> msgbox(ex.message & chr(10) & ex.LineNumber & chr(10) & ex.Source)<BR>End Try<BR><BR>Remember to catch the correct exception... Ex: if the error is occuring because of a DB problem, then catch the sqlException.

4. Senior Member
Join Date
Dec 1969
Posts
655

## RE: Are you using Try Catch??

Thanks I didn&#039;t see that LineNumber was a member of exception. I will give it a try.<BR><BR>Thanks again,<BR><BR>Morgan

5. Senior Member
Join Date
Dec 1969
Posts
655

## 'LineNumber' is not a member of 'Sy

Humm this is kind of what I though, linenumber is not a member of the exception class. Shoot! Any other ideas?<BR><BR>Morgan

6. Member
Join Date
Dec 1969
Posts
40

## RE: 'LineNumber' is not a member of 

I did not mean "linenumber" specifically, perhaps one of the other properties will give you the line number. I suggest you try all of them to see what you get instead of just ex.ToString().<BR><BR>If that doesn&#039;t work, then just do something like this.<BR>----------------<BR>catch (Exception e)<BR>{<BR>String origErr = e.ToString();<BR>String newErr = "There was an error connecting to the database...
" + origErr;<BR><BR>emailfunction(new Exception(newErr));<BR><BR>}<BR>------------<BR>That way, you can include your own little notes right in the new exception.

7. Senior Member
Join Date
Dec 1969
Posts
164

## What's kind of Exception are you catching??

First of all, if you&#039;re catching exceptions, then you should already have a good idea of what&#039;s failing.... what&#039; ever you encapsulated in the Try/End Try... <BR>If you&#039;re catching a exception of the "Exception" class, then LineNumber isn&#039;t available for you... but if you&#039;re handling more specific exception such as a sqlclient one, then use the SQLException which allows more description about exceptions.<BR>If this is unclear, try posting the code.

8. Senior Member
Join Date
Dec 1969
Posts
655

## RE: What's kind of Exception are you catching

I&#039;m actually catching errors in the global.asax file with this code.<BR><BR>Dim objMail As New MailMessage<BR>Dim ErrMessage As Exception = Server.GetLastError<BR>Dim strVariable as String <BR><BR>objMail.BodyFormat = MailFormat.Html<BR>objMail.From = "MyWebPage.com"<BR>ObjMail.To = "development@MyWebPage.com"<BR>objMail.Subject = ".NET Error on Live Server"<BR>objMail.Body = "Page" &Request.Path<BR>objMail.Body &= "Error Message:" &Server.GetLastError.Message <BR>&#039;objMail.Body &= "Line Number:" &Server.GetLastError.LineNumber<BR>objMail.Body &= "Error InnerException:" &Server.GetLastError.InnerException.ToString<BR>ob jMail.Body &= "Error Source:" &Server.GetLastError.Source <BR>objMail.Body &= "Error StackTrace:" &Server.GetLastError.StackTrace <BR>objMail.Body &= "Remote IP:" &Request.ServerVariables("REMOTE_ADDR") <BR>objMail.Body &= "Browser Type:" &Request.ServerVariables("HTTP_USER_AGENT") <BR>objMail.Body &= "Time:" &Now() <BR>objMail.Body &= "QueryString:" &Request.QueryString.ToString() <BR>objMail.Body &= "Session:" <BR>for each strVariable in Session.Contents<BR>objMail.Body &strVariable &":" &Session(strVariable) <BR>next<BR>objMail.Body &= "Form:"<BR>For each strVariable in request.form<BR>objMail.Body &strVariable &":" &request.form(strVariable) <BR>Next<BR>SmtpMail.SmtpServer = mail.mywebpage.com <BR>SMTPMail.Send(objMail)<BR>Context.Server.Clear Error()<BR><BR>Sorry if its a little messy and thanks for they help

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•