Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Handling Exceptions

Reply
Thread Tools

Handling Exceptions

 
 
Shahar Nechmad
Guest
Posts: n/a
 
      10-18-2006
I want to be able to log all exceptions that occur in the application (I'm
using Enterprise Library and ASP.NET 2.0). Because with almost all exception
I'm not going to do anything besides logging, I prefer dealing with it in
one central place instead of writing try catch statements all over the
place.
I know I can catch all the application exception using the Application_Error
event in the Golab.asax file, but the method doesn't seem to get the
exception as parameter.

How can I log all exceptions from one central place?


 
Reply With Quote
 
 
 
 
Karl Seguin [MVP]
Guest
Posts: n/a
 
      10-19-2006
You're on the right track...

Here's the code from an HttpModule I use (you can put it in your global.asax
if you want):

public void application_Error(object sender, EventArgs e)
{
HttpContext ctx = HttpContext.Current;
//get the inner most exception
Exception exception;
for (exception = ctx.Server.GetLastError(); exception.InnerException !=
null; exception = exception.InnerException) { }
if (exception is HttpException &&
((HttpException)exception).GetHttpCode() == 404)
{
logger.Warn(string.Format("A 404 occurred:
{0}",((HttpApplication)sender).Request.Url.ToStrin g() ), exception );
}
else
{
logger.Error(string.Format("ErrorModule caught an unhandled exception
on page {0}", ((HttpApplication)sender).Request.Url.ToString() ),
exception);
}
ctx.Server.ClearError();
ctx.Response.Redirert("error.aspx");
}

I'm using Log4net, but that's just a matter of changing the "logger.Warn"
and "logger.Error"



--
http://www.openmymind.net/
http://www.fuelindustries.com/


"Shahar Nechmad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I want to be able to log all exceptions that occur in the application (I'm
>using Enterprise Library and ASP.NET 2.0). Because with almost all
>exception I'm not going to do anything besides logging, I prefer dealing
>with it in one central place instead of writing try catch statements all
>over the place.
> I know I can catch all the application exception using the
> Application_Error event in the Golab.asax file, but the method doesn't
> seem to get the exception as parameter.
>
> How can I log all exceptions from one central place?
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exceptions - How do you make it work like built-in exceptions? Lie Python 3 01-14-2008 06:45 PM
Exceptions + Performance on path without exceptions gratch06@gmail.com C++ 3 04-16-2007 08:52 PM
Handling Exceptions in an n-tier environment Raterus ASP .Net 6 08-24-2004 08:21 PM
Checked exceptions vs unchecked exceptions Ahmed Moustafa Java 5 07-14-2004 01:46 PM
Custom exceptions -- inherit from exceptions.Exception? Paul Miller Python 3 11-12-2003 09:24 AM



Advertisments