473,506 Members | 16,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application Level Error Handling Question

I have added code to my Application_Error sub in Global.ASAX so that
whenever an error occurs in my ASP.NET application - it sends me an
email with the error information. However the information that I am
receiving doesn't have everything I would like. It doesn't give the
exact line of code and the exact place where the error occurred. Can
anyone help me with the code? I would like it to send me the same type
of information that you would see on the screen when an error occurs.
Here is the code that I am using in my Application_Error sub: (VB)

******************************
Dim ex As Exception = Server.GetLastError.GetBaseException
Dim strMessage As String
strMessage = "MESSAGE: " & ex.Message & vbCrLf & _
"SOURCE: " & ex.Source & vbCrLf & _
"STACKTRACE: " & ex.StackTrace & vbCrLf & _
"TARGETSITE: " & ex.TargetSite.ToString & vbCrLf & _
"REMOTEIP: " & Request.UserHostAddress
******************************

Then it emails me the strMessage string. An example of the email that
I receive is below:

******************************
MESSAGE: Object reference not set to an instance of an object.

SOURCE: MyApp

STACKTRACE: at MyApp.testPage.Page_Load(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain()

TARGETSITE: Void Page_Load(System.Object, System.EventArgs)

REMOTEIP: 127.0.0.1
******************************

The stacktrace is kind of helpful but it doesn't point me to a
particular line of code like a normal error message that you would see
on screen does.

Thanks,
Corey

May 12 '06 #1
3 1533
You would have to use a Debug build to get that information.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Corey B" <co***********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
I have added code to my Application_Error sub in Global.ASAX so that
whenever an error occurs in my ASP.NET application - it sends me an
email with the error information. However the information that I am
receiving doesn't have everything I would like. It doesn't give the
exact line of code and the exact place where the error occurred. Can
anyone help me with the code? I would like it to send me the same type
of information that you would see on the screen when an error occurs.
Here is the code that I am using in my Application_Error sub: (VB)

******************************
Dim ex As Exception = Server.GetLastError.GetBaseException
Dim strMessage As String
strMessage = "MESSAGE: " & ex.Message & vbCrLf & _
"SOURCE: " & ex.Source & vbCrLf & _
"STACKTRACE: " & ex.StackTrace & vbCrLf & _
"TARGETSITE: " & ex.TargetSite.ToString & vbCrLf & _
"REMOTEIP: " & Request.UserHostAddress
******************************

Then it emails me the strMessage string. An example of the email that
I receive is below:

******************************
MESSAGE: Object reference not set to an instance of an object.

SOURCE: MyApp

STACKTRACE: at MyApp.testPage.Page_Load(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain()

TARGETSITE: Void Page_Load(System.Object, System.EventArgs)

REMOTEIP: 127.0.0.1
******************************

The stacktrace is kind of helpful but it doesn't point me to a
particular line of code like a normal error message that you would see
on screen does.

Thanks,
Corey

May 12 '06 #2
You would have to build it in Debug mode. The binary built using the
Debug mode contains line number and other information. It is best
practice not to run in Debug mode in production environment.

May 12 '06 #3
Thanks for the confirmation. I did a little more searching and found
that indeed I need to build in Debug mode instead of Release mode to
get the line numbers.

Thanks,
Corey

May 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1523
by: Jason MacKenzie | last post by:
I have a production critical windows forms application. I have try catch blocks everywhere to handle every eventuality. However occasionally, every couple of months, the application crashes. Its...
1
1965
by: metsys | last post by:
We have an ASP.NET 2.0 (C#) application that is divided into multiple layers. The multiple layers come from having a web project and 2 different class library projects in the same solution. I'm...
0
2165
by: Maciek | last post by:
Hi, I have this question regarding SQL Server error 3621: "The statement has been terminated." and trapping it in Try...Catch block. I've written sample Stored Procedure which intentionally...
3
2310
by: Doug | last post by:
Using Visual Studio 2005, SQL Server 2000, and ASP.NET/VB.NET for a Web Application. We have a System DSN using Windows NT authentication defined on the development box to connect to the SQL...
4
2164
by: David Lozzi | last post by:
Howdy, I found a nice little book called ASP.NET 2.0 Cookbook by Michael A Kittel and Geoffrey LeBlond. Anyway, they have some instructions on how to setup application level error handling. Most...
0
3591
by: David Lozzi | last post by:
Howdy, I'm working on some error handling for my application. Currently on WinXP Pro SP2. Basically this is what I'm doing: Try...Catch at the method level, Catch sends email with error ...
3
1228
by: Paul | last post by:
Looking for recommendations on a programming language for a web application. I am soliciting recommendations on a programming language for a web application described below. Actually, it is not...
8
3318
by: Rodrigo Juarez | last post by:
Hi I'm using Visual Studio 2005 with visual basic, developing winforms applications I'm adding try catch blocks for error handling and I want to close the application when I got an error....
4
3188
by: dave m | last post by:
I'm creating a class library (dll) and am confused as how to pass any information, should any exceptions occur, back to the calling application. Such as: Try x = 3 / 0 ' divide by 0 error...
2
1495
by: nguyenminhhai | last post by:
Hi everyone, I'm reading "The C++ Programming Language" (Bjarne Stroustrup, 3rd edition). At page 193, he said "Doing error handling using the same level of abstraction as the code that caused the...
0
7218
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.