Thanks Richard, i'll do that.
> "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/exce
ptdotnet.asp
> If you are using the application block maybe you have already looked at
> this? Perhaps you're looking for something more specific?
[quoted text clipped - 25 lines]
> Hope this helps.
> Richard.
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.
> "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/exce
ptdotnet.asp
> If you are using the application block maybe you have already looked at
> this? Perhaps you're looking for something more specific?
[quoted text clipped - 25 lines]
> Hope this helps.
> Richard.
richlm - 26 Nov 2004 22:11 GMT
Good points Paul!
RAISERROR makes me think of assembly language, VB3.0, GOTO and line numbers.
It is just so primitive.
Choose the language and platform that is appropriate for the job.
If you really do need to distinguish between different types of constraint
violation in the database AND you need to handle them specifically in your
application code, then maybe it's justified to use RAISEERROR. Use it if you
have some chance of recovering from the situation.
If all you need to do is log it and tell the user it didn't work there is no
point. There should be sufficient text in the SqlException to identify what
the problem was.
"Hitting' the database used to be considered costly in terms of performance,
but I don't believe that is longer the case.
Let the database do what it is there for - let it tell you a constraint was
violated and handle it where you feel most comfortable - for me that's in my
C# code.
I also want all my business logic in one place - I don't want it in the
database since I'm a C# developer.
I could go on on this topic but I think I'll leave it here....
Richard.