473,486 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Exceptions Best Practice

asp.net 2.0 vs2005

What is best practice for exception handling on a website in vs2005?
I was going to catch errors in application on_error event, log them to the
event log, then send users to an error page. But looking at the event log,
asp.net 2.0 logs those errors anyways, with more detail than i cen get from
the exception object. So is there any point logging them to the event log, is
it jsut better to let .net do this and get the more information, and jsut
have the 0n_error event handler re-direct to the custom error page?
Jsut wondering what other people do?

Nov 3 '07 #1
5 2455
I normally redirect to an aspx page in the onerror handler and then have
the aspx page send me an email with the error information. That way, 1) I
am aware that there was a problem and 2) the error "logging" is less
likely to fail due to environmental issues.

I don't normally have easy access to the server. In your case, I might
reduce it to just sending an email notifying me that there was an error
until you find that you need more information.

-----Original Message-----
From: Billy [mailto:Bi***@discussions.microsoft.com]
Posted At: Saturday, November 03, 2007 6:11 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Exceptions Best Practice
Subject: Exceptions Best Practice

asp.net 2.0 vs2005

What is best practice for exception handling on a website in vs2005?
I was going to catch errors in application on_error event, log them to the
event log, then send users to an error page. But looking at the event log,
asp.net 2.0 logs those errors anyways, with more detail than i cen get
from
the exception object. So is there any point logging them to the event log,
is
it jsut better to let .net do this and get the more information, and jsut
have the 0n_error event handler re-direct to the custom error page?
Jsut wondering what other people do?

Nov 3 '07 #2
So is there any point logging them to the event log

We had some third party guys develop an asp.net app which logged
errors in the event log and to be honest, it's a nightmare because you
can't always get onto the server to view it.

I would highly recommend using log4net - it's free and really is very
easy to get it up and running yet powerful enough to enable you to get
many levels of logging and info out of your app. See
http://www.designforge.com/df/design/log4net.htm for a very simple way
of getting going with it (it works for both .net 2.0 and 1.1).

Nov 3 '07 #3
Hello Billy,

read there http://msdn2.microsoft.com/en-us/library/aa479319.aspx

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
Basp.net 2.0 vs2005
B>
BWhat is best practice for exception handling on a website in vs2005?
BI was going to catch errors in application on_error event, log them
Bto the
Bevent log, then send users to an error page. But looking at the event
Blog,
Basp.net 2.0 logs those errors anyways, with more detail than i cen
Bget from
Bthe exception object. So is there any point logging them to the event
Blog, is
Bit jsut better to let .net do this and get the more information, and
Bjsut
Bhave the 0n_error event handler re-direct to the custom error page?
BJsut wondering what other people do?
Nov 3 '07 #4
the enterpriselibrary.logging (.database) is an option
log4net is another.
I define one class with a static method that I encapsulate what I need
(logging, etc).

then either the use can get the error, or do a redirect.

If the exception is a unique constraint issue (SSN for example), then
showing them the issue on the same page is good I think.
If its a db is gone type error, then a redirect to a page is good.
public class ThisApplicationExceptionThinger

public static LogException (Page p , Exception ex , bool redirect )
{
//do something with the error, like the EnterpriseLibrary.Logging

if(redirect)
{
p.Response.Redirect("~/showexceptiontouser.aspx");
}

}

Something like that.
You can either querystring the msg or put it in the Session temporary.
"Billy" <Bi***@discussions.microsoft.comwrote in message
news:C8**********************************@microsof t.com...
asp.net 2.0 vs2005

What is best practice for exception handling on a website in vs2005?
I was going to catch errors in application on_error event, log them to the
event log, then send users to an error page. But looking at the event log,
asp.net 2.0 logs those errors anyways, with more detail than i cen get
from
the exception object. So is there any point logging them to the event log,
is
it jsut better to let .net do this and get the more information, and jsut
have the 0n_error event handler re-direct to the custom error page?
Jsut wondering what other people do?

Nov 4 '07 #5
Been using this for emailing notification of website errors for a few years
on a number of sites :

http://msdn2.microsoft.com/en-us/library/aa479332.aspx
"Billy" <Bi***@discussions.microsoft.comwrote in message
news:C8**********************************@microsof t.com...
asp.net 2.0 vs2005

What is best practice for exception handling on a website in vs2005?
I was going to catch errors in application on_error event, log them to the
event log, then send users to an error page. But looking at the event log,
asp.net 2.0 logs those errors anyways, with more detail than i cen get
from
the exception object. So is there any point logging them to the event log,
is
it jsut better to let .net do this and get the more information, and jsut
have the 0n_error event handler re-direct to the custom error page?
Jsut wondering what other people do?

Nov 5 '07 #6

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

Similar topics

0
2446
by: seth | last post by:
Last week I encountered an AttributeError in my unit tests that I wasn'table to catch with an "except AttributeError" statement. The problem stemmed from a class that raised an error inside...
2
1698
by: Martin Smith | last post by:
If a class has no need for any specific clean up code in a particular catch block is there any benefit to catching and rethrowing exceptions, rather than just letting the original exception bubble up...
10
1750
by: Brian Folke Seaberg | last post by:
I was recently browsing a couple of C++ books at the local bookstore. One book called throwing exceptions from constructors a "dubious practice." Another book recommended not throwing...
4
1801
by: Johannes Hansen | last post by:
What are the best practice on handling an exception caused by a Dispose method when its called from inside a loop? Wrap the entire loop in a try-catch or do the try-catch on each iteration to get...
136
9198
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
22
2695
by: Drew | last post by:
How do I know which exceptions are thrown by certain methods? For example, reading a file might throw an IO Exception, etc. In Java, the compiler won't even let you compile unless you put your...
14
3448
by: dcassar | last post by:
I have had a lively discussion with some coworkers and decided to get some general feedback on an issue that I could find very little guidance on. Why is it considered bad practice to define a...
5
1812
by: seenutn | last post by:
Hi, These questions are on C++ and Exceptions. 1) How can I debug through gdb to find the location where exception occured (Putting a breakpoint in exception handler will not help me as the...
3
3345
by: redefined.horizons | last post by:
I'm new to C#, (coming from a Java programming background), and I have a question about the correct use of exceptions. My book "Programming C#" by O'Reilly says the following in Chapter 11,...
0
7099
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
6964
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
7319
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4864
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
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
3069
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
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
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.