473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Frustrations with Error Logging

Hi

From classic ASP, I had a custom error handling situation that was
quite simple. Errors were all redirected to Error.asp. This page would
check 2 settings, EmailErrorMessage and DisplayErrorMessage. If
EmailErrorMessage was true, it would send an email with the error
details. If DisplayErrorMessage was true, it would display the message
on screen. Also, if an Administrator was logged in, it would display
the message as they could then handle it.

Now in .NET this is proving EXTREMELY frustrating.

Please correct me if my logic here is wrong: In the web.config file, I
can add the lines:
<customErrors mode="On" defaultRedirect="/Error.aspx">
<error statusCode="400" redirect="/Error.aspx?err=400" />
<error statusCode="401" redirect="/Error.aspx?err=401" />
<error statusCode="403" redirect="/Error.aspx?err=403" />
<error statusCode="404" redirect="/Error.aspx?err=404" />
<error statusCode="408" redirect="/Error.aspx?err=408" />
<error statusCode="500" redirect="/Error.aspx?err=500" />
<error statusCode="503" redirect="/Error.aspx?err=503" />
</customErrors>

That looks like an elegant and simple solution. BUT, error.aspx won't
have access to the error object as this is effectively a redirect, and
the error object is lost.

Now I've seen that you can ("should") handle your error in the
Global.asax area and then transfer to a simple HTML page. But this is
just stupid. Firstly, I'm filling up my global.asax with error
handling code. Secondly, I can send the email with the error info from
this point, but when I redirect to the error page, I lose the ability
to display the error message on screen to administrators.

SO, I can try putting this into global.asax:
void Application_Error(object sender, EventArgs e)
{
Server.Transfer("/Error.aspx");
}

BUT, when this gets to my error page, this new error object doesn't
have the info I would like. I get the error with:
Exception objError = Server.GetLastError().GetBaseException();

But this doesn't have the error code, or line number, etc. I would
like to (for example) be able to filter out the 404 errors, as these
can be handled with a simple redirect to the home page, as that
content has moved, and it's not worth showing an error page for it.
But I can't do that now!

I don't get this new logic. For example, it's got a property
objError.Source, which gives a result: "System.Web". Of course &(%@
System.Web created the error - it's a website system!!!!!

Why did they take away the very simple and useful Line Number and
Error Number (error code)???

Anyone got a good idea on what to do?
Jul 30 '08 #1
1 1753


Here is one way to make a helper call.

Create a class.
public class WebPageExceptionWrapper
{

public static void HandleException( Page p , Exception ex ) //by sending
in the Page, you have alot of control for redirects and stuff
{
if(null==p)
{
return;
}

p.Response.Write (ex.Message);

bool redirect = true; //just a crappy way to show you can optionally
redirect.
if(redirect)
{
p.Response.Redirect(http://www.microsoft.com);
}

}
}

then on your aspx.cs files
public void TrySomething()
{

try
{
int i = 0;
int j = 0;
int k = i/j;

}
catch(Exception ex)
{
WebPageExceptionWrapper.HandleException(this.Page , ex);
}

}

Unforunately, I cannot agree with you on the "helpful error numbers".
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!234.entry
Exception Handling is a slightly different mindset (as opposed to
errorhandling in vb/asp terms).
And IMHO is a much better solution.

Follow my blog entry and find the great article by Krzysztof Cwalina.

Good luck on your endeavors.
This is ONE idea. There are others. But I think this is a good "bridge the
gap" idea for you coming from asp.

"sean_walsh" <se**************@hotmail.comwrote in message
news:32**********************************@r66g2000 hsg.googlegroups.com...
Hi

From classic ASP, I had a custom error handling situation that was
quite simple. Errors were all redirected to Error.asp. This page would
check 2 settings, EmailErrorMessage and DisplayErrorMessage. If
EmailErrorMessage was true, it would send an email with the error
details. If DisplayErrorMessage was true, it would display the message
on screen. Also, if an Administrator was logged in, it would display
the message as they could then handle it.

Now in .NET this is proving EXTREMELY frustrating.

Please correct me if my logic here is wrong: In the web.config file, I
can add the lines:
<customErrors mode="On" defaultRedirect="/Error.aspx">
<error statusCode="400" redirect="/Error.aspx?err=400" />
<error statusCode="401" redirect="/Error.aspx?err=401" />
<error statusCode="403" redirect="/Error.aspx?err=403" />
<error statusCode="404" redirect="/Error.aspx?err=404" />
<error statusCode="408" redirect="/Error.aspx?err=408" />
<error statusCode="500" redirect="/Error.aspx?err=500" />
<error statusCode="503" redirect="/Error.aspx?err=503" />
</customErrors>

That looks like an elegant and simple solution. BUT, error.aspx won't
have access to the error object as this is effectively a redirect, and
the error object is lost.

Now I've seen that you can ("should") handle your error in the
Global.asax area and then transfer to a simple HTML page. But this is
just stupid. Firstly, I'm filling up my global.asax with error
handling code. Secondly, I can send the email with the error info from
this point, but when I redirect to the error page, I lose the ability
to display the error message on screen to administrators.

SO, I can try putting this into global.asax:
void Application_Error(object sender, EventArgs e)
{
Server.Transfer("/Error.aspx");
}

BUT, when this gets to my error page, this new error object doesn't
have the info I would like. I get the error with:
Exception objError = Server.GetLastError().GetBaseException();

But this doesn't have the error code, or line number, etc. I would
like to (for example) be able to filter out the 404 errors, as these
can be handled with a simple redirect to the home page, as that
content has moved, and it's not worth showing an error page for it.
But I can't do that now!

I don't get this new logic. For example, it's got a property
objError.Source, which gives a result: "System.Web". Of course &(%@
System.Web created the error - it's a website system!!!!!

Why did they take away the very simple and useful Line Number and
Error Number (error code)???

Anyone got a good idea on what to do?

Jul 30 '08 #2

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

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
5
by: Tony Wright | last post by:
Hi, I am having a problem installing an msi for a web site. The error message I am getting is: "The specified path 'http://mipdev05/features/Fas2' is unavailable. The Internet Information...
10
by: Brian Conway | last post by:
I have no idea what is going on. I have a Login screen where someone types in their login information and this populates a datagrid based off of the login. Works great in debug and test through...
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
4
by: sm | last post by:
Hi, I have a couple of questions with regards to handling errors and exceptions. 1. If I use On Error goto Errhandler ... Errhandler:
7
by: flupke | last post by:
Hi, i'm getting errors with the log module concerning RotatingFileHandler. I'm using Python 2.4.3 on Windows XP SP2. This used to work in previous python versions but since i upgraded to 2.4.3...
0
by: Roopesh | last post by:
Hi I am trying to use RotatingFileHandler, in the foll way : rootLogger = logging.getLogger('') rootLogger.setLevel(logging.DEBUG) rotatingHandler =...
9
by: Rasika WIJAYARATNE | last post by:
Hi guys, Please check this out: http://rkwcoding.blogspot.com/2007/07/error-logging.html
2
by: =?Utf-8?B?UG9sbHkgQW5uYQ==?= | last post by:
Hi, I have been successfully using the EHAB & Logging Application Block. Now however I get the error below and looking on line I was told that I have not set references to all the dlls. I have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.