Subject: How to handle error or exception if it occurs
Posted By: popoxinhxan Post Date: 8/17/2006 8:19:05 PM
How can i manage the exeception in thebeerhouse, should i manage them on the BLL or presentation layer. For example, assume that admin can be able to update the category but category name must e unique i.e when i tried to update the category name it show exception  System.Data.SqlClient.SqlException: Cannot insert duplicate key row in object
what i would like is to capture this and display user friendly message to user instead of the errorpage. How can i do it?
Thank you

Reply By: englere Reply Date: 8/17/2006 11:22:40 PM
That's the question of the ages and there's no single right answer. It depends on how you want to handle the error. If you want to deal with it in the UI layer that that's not a bad place to put the exception handler.

Of course, it's best to modify the code so that no routine actions of a user can trigger an excpetion. But you shouldn't be paranoid about testing for everything up front so you should also design in exception handling.

I always include logging with exception handlers because it can alert me to design weaknesses that need to be addressed.

Eric

Reply By: popoxinhxan Reply Date: 8/22/2006 8:07:06 PM
I understood your points however the error occurs in the DAL
conn.Open();
int ret = cmd.ExecuteNonQuery(); //Error here when i tried to updated exist value
return (ret == 1);

I tried to catch Exception(TargetInvocationException) in the BLL and display appropriate user friendly message, However it won't work instead redirect to default error page in Asp.net
Server Error in 'thebeerhouse' Application...

One more problem is that how can i log the error in the text file. in the WebCustomEvent , Macro only provide the way to recorddelete event using health monitoring however there is not method is use to log if unexpected exception occurs

Can you give me some advices about this.

Reply By: englere Reply Date: 8/27/2006 6:44:45 PM
I'm guessing it's a different exception, and therefore you didn't really catch it. Why not catch any kind of exception, and then test to see what it was?

Health monitoring isn't a good way to log errors. Do some research on a custom trace listener. It's used for both debug and trace messages. The TextFileTraceListener is a good choice to log to a file. You also need to ensure that your ASPNET user account has write access to that file.


Go to topic 48777

Return to index page 192
Return to index page 191
Return to index page 190
Return to index page 189
Return to index page 188
Return to index page 187
Return to index page 186
Return to index page 185
Return to index page 184
Return to index page 183