Hello ! I'm developping an ASP.net 2.0 application. I'm wondering how to make an usable and easy way to handle errors and exceptions. I mean, everytime i make a "try {...} catch {... }" i need to intercept the exceptin and : -> give to the user an understandible
message, not an error code unreadable or stack trace. -> keep a log of the event (Sql Server Database in my case ) -> send an email to the Admin (me :o) ) to alert him about some critical problem. and all that by one unique way.... easy to call... :o) ( like
: try {...} catch (Exception ex) { ErrorManager( ex, "My readable custom error comment to display at the user", // maybe redirect to a template page (using the MasterPage site so It keeps the general look) displaying this custom message.... true, // boolean
indicates if sendEmailToAdmin true, // boolean indicates if log in Sql Server ... and other nice options if you find more ); } By calling this method, everything is handled in a right way. Do you have some idea ? project examples are welcome :-) I've tried
to use the healthMonitoring features of Asp.Net 2.0 to send emails, but I still can't help (even reading the good Fredrik Normén's Article, telling how to use it). I'm wondering if I have to configure some SMTP parameters ? How ? Where (web.config) ? (I'm
for the moment using my machine as server, so I launch my project in localhost, can I use an existing mail SMTP server used for my personal emails accounts...) I think it wouldn't be to hard to find a cool way to handle all this, but I need your help to give
me some indications about how can I do it "for best" and easier... Thank you in advance. Miketrix
-- Miketrix
Better to know much about nothing or to a little about everything ?
thank's for the links .... I would rather like to use the latest features provided by ASP.net 2.0 which I think they're powerful to handle Exceptions (HealthMonitoring -> SqlWebEventProvider / SimpleMailWebEventProvider / ...) I just don't know how really achieve
that in a right way. Do I have to make a class that inherits from WebErrorEvent or something like that (I read an article about it but without finding real explanation)... Anyone did try some solution that : -> gives to the user an understandible message,
not an error code unreadable or stack trace. -> keeps a log of the event (Sql Server Database in my case ) -> sends an email to the Admin (me :o) ) to alert him about some critical problem. All this wrapped in a class easy to adapt/use ? If not, is anyone
interested to talk about it in private with me (email/msn/...) and maybe build it together ? I think it would be great to find a reusable implementation that could be used in many ASP.net 2.0 projects. Best regards Miketrix
-- Miketrix
Better to know much about nothing or to a little about everything ?
I would rather like to use the latest features provided by ASP.net 2.0 which I think they're powerful to handle Exceptions (HealthMonitoring -> SqlWebEventProvider / SimpleMailWebEventProvider / ...)
These new features don't handle exceptions and they don't replace the Application_Error event notification. They certainly can be used in conjunction with them, though. I could easily see putting a health monitoring even in Application_Error (and in fact,
ASP.NET already does one here -- you can see it in the EventLog, as that's the default logging location). -Brock
Ok, that's one reason why I'm asking you to help me because I don't really understand how and where it's the best place ( in code) to handle notifications/exceptions ... Those features don't handle exceptions of course, but they provide an easy way to get some
notification (by mail, by SQL, by Windows Event Log, ...). I'm thinking about making a static class that could be called from anywhere in my application and provides all the notification mecanism behind... So it becomes easy to handle exceptions in my 'try
& catch' ... But I have no idea about how to code it ... Reading the Fredrik Normén's Blog i tryed the following code in the onClick event of a simple button : WebBaseEvent myEvent = new WebErrorEvent("My Error Message", null, 5000, ex); myEvent.Raise(); I
get this error : Error : 'System.Web.Management.WebErrorEvent.WebErrorEvent(string, object, int, System.Exception)' is inaccessible due to its protection level c:\inetpub\wwwroot\site01\societe.aspx.cs :o( any idea ? Thank's to all for this really nice forum
! Miketrix
-- Miketrix
Better to know much about nothing or to a little about everything ?
Miketrix
Member
195 Points
39 Posts
Best Practices for Exceptions and Errors handling...
Mar 18, 2005 10:44 AM|LINK
Better to know much about nothing or to a little about everything ?
BrockAllen
All-Star
27516 Points
4898 Posts
MVP
Re: Best Practices for Exceptions and Errors handling...
Mar 18, 2005 01:50 PM|LINK
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
Miketrix
Member
195 Points
39 Posts
Re: Best Practices for Exceptions and Errors handling...
Mar 18, 2005 02:27 PM|LINK
Better to know much about nothing or to a little about everything ?
BrockAllen
All-Star
27516 Points
4898 Posts
MVP
Re: Best Practices for Exceptions and Errors handling...
Mar 18, 2005 07:04 PM|LINK
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
Miketrix
Member
195 Points
39 Posts
Re: Best Practices for Exceptions and Errors handling...
Mar 20, 2005 10:59 AM|LINK
Better to know much about nothing or to a little about everything ?