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)
{
try
{
//My DAL code to insert data to database
}
catch (SqlException ex)
{
throw 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.
Regards,
Akhil Raj K R
Please Mark as Answer if it helps u...
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.
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
Regards,
Akhil Raj K R
Please Mark as Answer if it helps u...
akhilrajau
Participant
1744 Points
537 Posts
Exceptions categories need to handle in each laayer of layered application
Apr 16, 2012 12:18 PM|LINK
hi all,
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) { try { //My DAL code to insert data to database } catch (SqlException ex) { throw 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.
Akhil Raj K R
Please Mark as Answer if it helps u...
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Exceptions categories need to handle in each laayer of layered application
Apr 16, 2012 08:12 PM|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.
Blog | Twitter : @Hattan
akhilrajau
Participant
1744 Points
537 Posts
Re: Exceptions categories need to handle in each laayer of layered application
Apr 17, 2012 02:17 AM|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
Akhil Raj K R
Please Mark as Answer if it helps u...