Good Day.
Sorry to interject, but I was thinking about implementing RAISERROR within
my sprocs for things like ForeignKey constraints & CHECK Constraints.
RAISERROR would have thrown an exception with my own unique error number,
thus enabling me to handle any problems for example -:
Event Foreign Key Constraint: 'The Supplier chosen may have been deleted."
Event CHECK Constarint: 'Please specifiy a Supplier Type between 1 & 3'.
OK, the last error could actually be handled in the BL layer but I dont want
my application to show a general error message that could quite possible
relate to any number of named constraints.
Would you set up your database using Declarative Referential Integrity as a
failsafe method but use the BL layer to check for these constraints prior to
Inserting, Updating & Deleting?
If the answer is yes then would you execute the statements as individual
transactions, i.e.
BLObjMethod_InsertSupplierProduct
{
BLmethod_ValidateSupplierTypeRange(...);
DALmethod_CheckSupplierExists(...); <-- DB access required.
DALmethod_CheckProductTypeExists(...); <-- DB access required.
...
}
or would you attempt to control the transactions from the BL layer, i.e.
BLObjMethod_InsertSupplierProduct
{
BLmethod_ValidateSupplierTypeRange(...);
DALmethodBeginTrans();
DALmethod_CheckSupplierExists(...); <-- DB access required.
DALmethod_CheckProductTypeExists(...); <-- DB access required.
DALmethodEndTrans();
...
}
or would you make your DAL a bit more intelligent, i.e.
DALObjMethod_InsertSupplierProduct
{
methodBeginTrans();
method_CheckSupplierExists(...); <-- DB access required.
method_CheckProductTypeExists(...); <-- DB access required.
methodEndTrans();
...
}
I hope the above makes some sense and your answers would be greatly
appreciated.
Just like Gai it seems hard to find definitive answers or the 'Very Best of
Practices'.
Kind Regards
Paul Johnson.
[quoted text, click to view] "richlm" <rich_lm@h0tmai1.com> wrote in message
news:ejI7yaz0EHA.3364@TK2MSFTNGP12.phx.gbl...
> "Exception Management Architecture Guide" from Microsoft patterns and
> practices contains most (if not all) of the useful best practices I am
aware
> of in relation to structured exception handling. It's an excellent general
> reference.
>
> You can find it here:
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/exceptdotnet.asp
>
> If you are using the application block maybe you have already looked at
> this? Perhaps you're looking for something more specific?
>
> I think the guide provides answers to your questions 1-3, but here's my
> interpretation/view:
> 1. Only if it makes sense. Do you need to log or audit it at the server?
> Does it matter if it gets lost on the way from server to client? Is it
> relevant to show it to the user? Can the server recover without bothering
> the user? Do you need to add some context before passing it to the client?
> 2. Again - only catch a specific exception if you can do something useful
> with it
> 3. It probably depends on whether you need to handle the exception as a
> special case. If a global exception handler can do the job, why clutter
your
> UI logic with exception handling.
>
> 4. This sounds like TOO fine a level of detail for exception handling. You
> should not use exception handling to implement business logic, and I have
a
> sneaky suspicion that's what you might be trying to do here when you are
> talking about "constraints" and "translate the message to the user". The
> user doesn't give a damn about constraints! In a really good
architecture
> (and UI design) the user should rarely (never?) be able to do something
that
> causes an exception.
>
> No you certainly don't want to end up with try catch blocks all over the
> place. Read the guide referenced above several times until you have the
> basic principles there implanted in your subconscious...
>
> Hope this helps.
> Richard.
>
>