Last post Apr 16, 2012 10:17 PM by akhilrajau
Apr 16, 2012 08:18 AM|akhilrajau|LINK
May be this is not a valid question but i need to know the best way. I read articles that dont catch general exception('Exception') in each method. Instead catch specific exceptions like SQLException etc. So based on this i haave doubts that what are the
exceptions need to handle in each layer?
I am using SOA architecture so all exceptions are converted in service layer. In DAL layer i am using try catch and in the catch block i thow the exception like below:
public void InsertUser(User user)
//My DAL code to insert data to database
catch (SqlException ex)
Parameter 'User' is business entity. Here only SQLException is needed? or any more? What i need to take base for identifying these types of Exceptions.
In business and service methods i am not using try -- catch. I generally handling in Service Layer aand convert to my Exception..Any further exception check in business layer?
In Presentation layer, i used try--catch in each method of aspx page.
Apr 16, 2012 04:12 PM|CodeHobo|LINK
The idea is to catch specific exceptions and allow generic exceptions to bubble up and hopefully have a logger in place to catch them. The problem is with a generic catch "exception" is that you might accidentally end up causing more problems by not handling
specific problems correctly. Your generic catch could solve a specific problem for you, but also catch a problem you did not account for and thus make debugging/fixing the problem even harder.
So to answer your question, it's on a case by case basis and really depends on what your code does. So you to explicitly handle every exception, but also put a logger in place to catch a generic exception and later handle them.
Apr 16, 2012 10:17 PM|akhilrajau|LINK
Thanks friend. So as your point my DAL layer handling is correct . am i right? In my exception handling in service layer i am logging this error in to the database. I used try..catch only in DAL and Presentation Layers only