Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 27, 2012 05:03 PM by eric2820
Dec 22, 2012 04:21 PM|LINK
when I have a method in code behind thqt has try code block. I can capture the error and post a message to the user.
I am ok with that. But, when I move the method to Data Access Layer, I cannot post a message instead, I throw the error... is this right,
so the calling method should have another catch try block to capture the raised error and post the messagee .
I appreciate your feedback on best way to post an error created in DAL
here is some code
I have some methods in Data Access tier of which it has try catch block. I want to discuss the catch block
like this one. so, if the code catch an sql client error, in DAL,
// calling a method in Data Access Layer
catch (SqlException SqlEx)
string SqlError = SqlEx.Message.ToString();
the code in DAL inside a method that generate the error
catch (System.Data.SqlClient.SqlException ex)
Dec 22, 2012 07:36 PM|LINK
If your going to catch exceptions, you should be able to handle them rather than just re-throw the exception.
At the very least you should be checking the exception for certain cases and reporting them directly.
Dec 27, 2012 04:58 PM|LINK
If I handled the exception in Business Layer or in Data Layer, how can I pass error message to the user in GUI tier?
Dec 27, 2012 05:00 PM|LINK
The 'old-school' method would be to return an error code that the application was aware of.
That is a good method to fall back to in the case where you can't come up with anything better.
Dec 27, 2012 05:03 PM|LINK
BTW. this is the basis of my earlier reply:
Why is it a bad idea to throw your own exceptions? Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own
exceptions signifies some design flaws in the project.