Custom errors and line numbers

B

Buddy Ackerman

When trapping unhandled errors in a web page via the Page_Error or
Application_Error event procedures is it possible to get the line number on
which the error occured? When not using custom error pages the default
error page displays the line number that the error occured on. Since this
page is not displayed I have no idea what the error actually is. The stack
trace usually isn't very helpful in determining what line caused the error
so even though I get notified of the error there is no telling where in the
code the error actually occured.


--Buddy
 
P

Patrice

If I remember, the doc states that this information is available in debug
mode with the pdb files...

The smaller each function is, the easier it is. You could also have some
additional information such as a session variable to track at which step you
are in a function...

For now in most cases it's quite easy to find out...
 
B

Buddy Ackerman

Patrice said:
If I remember, the doc states that this information is available in debug
mode with the pdb files...

How would you programatically access the line on which the error occurs?


The smaller each function is, the easier it is. You could also have some
additional information such as a session variable to track at which step you
are in a function...


IIS Sessions are evil and this requires me to add code to every page on my
site to track position within the script.


For now in most cases it's quite easy to find out...

and yet you have given me no easy way to find out.
 
B

Brock Allen

If I remember, the doc states that this information is available in
debug mode with the pdb files...

Yes, via Exception.StackTrace. Personally, I just call Exception.ToString()
and get everything there is to know about the exception, then log it so a
human can inspect it later.
 
P

Patrice

See :
http://msdn.microsoft.com/library/d...iagnosticsStackFrameClassGetFileNameTopic.asp
(GetFileName,GetFileNumber)
(thought it likely requires symbols)

For now based on the error message, I don't feel I had too much troubles
finding the offending line. It may :
- depends on the exact error (indexing error is likely esaier than a general
object reference not set)
- the samller the function the better is (as you have the function, if the
function is 20 lines it will be easier to find out than if it's 100 lines)
- defensive programming may help (ie. handle those case who shouldn't
happens now).

For now I never felt I had to get this information from the production box.

Sorry for the poor help.

Patrice

--
 
B

Buddy Ackerman

Patrice said:
If I remember, the doc states that this information is available in debug
mode with the pdb files...

How would one get this information programatically so that it could be
entered into a database?



The smaller each function is, the easier it is. You could also have some
additional information such as a session variable to track at which step you
are in a function...

This would require me to modify every page on my site.

For now in most cases it's quite easy to find out...

So, could you suggest one?
 
B

Buddy Ackerman

Unfortunately Exception.StackTrace doesn't give you very much info about the error. I am already entering this into my
errorlog and it's pretty much useless info. Here's an example of on StackTrace;


Stack Trace: at ASP.updateSongInfo_aspx.__Render__control1(HtmlTextWriter __output, Control parameterContainer)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Page.ProcessRequestMain()




This is pretty much the same thing I get on EVERY error regardless of the page. I just want to get the line number that
is displayed when CustomeErrors is Off and there is no redirect page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top