L
Liming
Hi,
In a typical 3 tier model (view layer, busines layer and data access
layer) where do you handle your exceptions? do you let it buble up all
the way to the .aspx pages or do you handle it in your business layer
and/or data access layer?
suppose in my data access layer, I provide try and catch, log the
exception and re-throw it back to business layer, then in yoru business
layer, what do you do? throw it back to the code behind or you handle
it right there?
Right now, here is my workflow.
1) I handle my exceptions in my data access layer, log it and return
an integer value back to top, so say for a Insert method, I return "0"
for failed insert and any postive integer (which will be primary key of
the the inserted database row) up to business layer.
2) Business layer then use this integer value to handle the approriate
actions (for example, if row is inserted, email to somebody) and return
the same value back to codebehind.
3) Codebehind checks if it's a 0 or a positive integer, if 0, then
display a message to user "insert failed, please contact yoru admin"
I have a feeling this is a bad pratice, but not sure why. Just then I
had this problem where two pages (1 user page and 1 admin page) are
accessing the same insert method. The user page just need to say "Error
occured while inserting, please contact your admin" (admin would in
term check the log files) and in the admin page however, we want to
directly tell them exactly what the exception is which in this case,
bubble up the exception would seem approriate.
So I realized my way of handling exception is hugely flawed, I'm
wondering how you guys handle your exceptions in your asp.net tierd
design?
Thanks a lot.
In a typical 3 tier model (view layer, busines layer and data access
layer) where do you handle your exceptions? do you let it buble up all
the way to the .aspx pages or do you handle it in your business layer
and/or data access layer?
suppose in my data access layer, I provide try and catch, log the
exception and re-throw it back to business layer, then in yoru business
layer, what do you do? throw it back to the code behind or you handle
it right there?
Right now, here is my workflow.
1) I handle my exceptions in my data access layer, log it and return
an integer value back to top, so say for a Insert method, I return "0"
for failed insert and any postive integer (which will be primary key of
the the inserted database row) up to business layer.
2) Business layer then use this integer value to handle the approriate
actions (for example, if row is inserted, email to somebody) and return
the same value back to codebehind.
3) Codebehind checks if it's a 0 or a positive integer, if 0, then
display a message to user "insert failed, please contact yoru admin"
I have a feeling this is a bad pratice, but not sure why. Just then I
had this problem where two pages (1 user page and 1 admin page) are
accessing the same insert method. The user page just need to say "Error
occured while inserting, please contact your admin" (admin would in
term check the log files) and in the admin page however, we want to
directly tell them exactly what the exception is which in this case,
bubble up the exception would seem approriate.
So I realized my way of handling exception is hugely flawed, I'm
wondering how you guys handle your exceptions in your asp.net tierd
design?
Thanks a lot.