Exception Handling.

R

Rajeev Soni

Hi,

Considering the scenario for handling exceptions in Web Application where we have Presentation layer, Business layer and Data Access layer; if there any exception is occurred in DAL, what is the best thing to do:

1. Dont catch the exception in DAL and let it prop up to the Application level and the Global.Application_Error event log it to any source and show let ASP.NET show custom error page provided in Web.Config file.

OR

2. Catch Exception in DAL, Log the error using some Exception Handling mechanism and Tranfer the control to another page using Server.Transfer("ErrorPage.aspx");

Which one of the above 1 or 2 is the best way to handle exceptions?

Regards
Rajeev Soni
 
R

Rajeev Soni

Hi,
Well i had a issue
1. Do i require to show Exception message to user
OR
2. Just to show same static Error message for any kind of errors

i thought there is no need for me to show the actual message to user, so i only required to log the error in some place before showing the custom static error page to user.

And here is what i did:
1. In the Global.asax.cs :
protected void Application_Error(Object sender, EventArgs e)
{
ExceptionManagement objEM = new ExceptionManagement();
objEM.HandleException();
}

2. And in ExceptionManagement class:
public void HandleException()
{
LogException();
if (SendMail)
MailException();
}

Is is right to use Global.Application_Error event to log errors
OR
Use try/catch where ever exception can occur?

Thanks and regards
Rajeev
 
W

Wim Hollebrandse

Best practice IMHO is to create your own custom Exception classes, catch the
Exceptions in your DAL, but re-throw your own custom exceptions with more
detailed info as to where the error occurred. They can then be dealt with in
the app which uses the DAL.

Hope that helps,
Wim Hollebrandse
http://www.wimdows.com
http://www.wimdows.net


Hi,

Considering the scenario for handling exceptions in Web Application where we
have Presentation layer, Business layer and Data Access layer; if there any
exception is occurred in DAL, what is the best thing to do:

1. Dont catch the exception in DAL and let it prop up to the Application
level and the Global.Application_Error event log it to any source and show
let ASP.NET show custom error page provided in Web.Config file.

OR

2. Catch Exception in DAL, Log the error using some Exception Handling
mechanism and Tranfer the control to another page using
Server.Transfer("ErrorPage.aspx");

Which one of the above 1 or 2 is the best way to handle exceptions?

Regards
Rajeev Soni
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top