Where should I handle exceptions in BLL, DAL or PL?

What is the best place to handle exceptions? BLL, DAL or PL?

Should I allow methods in DAL and BLL to exclude exceptions from the chain and let the PL handle them? Or should I process them in BLL?

eg

If I have a method in my DAL that returns “ExecuteNonQuery” and updates some records, and for one or more reasons, 0 rows will suffer. Now, how should I inform my PL about whether an exception occurred or if there really weren’t any rows matching the condition. Should I use "try catch" in my PL code and report it through the exception, or do I need to handle the exception in DAL and return some special code, for example (-1), to allow PL to distinguish between (exception) and (no line matches condition, i.e. zero lines are affected)?

+3
source share
7 answers

, DAL PL - , ?

, , , . - , .

+4

( , !) , s1mm0t, .

, , PL. . , ( (esp if web), ).

: () - " ". PL .NET : , (. EDIT ). , / ; , , , , , ( / ) >

, 'using' try/finally/end try catch. // / .. / , ( ).

(, -, IF , iffy , ), .

, , , /, ( - , ).

: , , , PL - - . , , BLL/DAL 3 PL: ASP.Net, winforms . , , BLL (DAL , ). , PL; - ( ); WinForms .. ( - "", ). , , , . , BLL, " ", winforms asp-, , .

+3

- !

, - . "- " , . , , , . (, ) , . @mbeckish , , , , , . ( ) finally , . , , , . , , , , , (, , ).

, "" , . , , . ? - , , , , .

.

+2

, , , , , . , , , DAL. , , , , , .

+1

. , . , , Enterprise Exception Block , .

http://msdn.microsoft.com/en-us/library/ff664698(v=PandP.50).aspx

, , .

0

. , DL. , . , .

. , , . , , , ? .

, / , . / . , .

, . . . , .

0

, ? , DAL. , BLL. , PL.

, DAL , null false - , BLL. BLL , , DAL , , , , .. PL, BLL DAL - .

Of course, you will not receive detailed messages about exceptions, but this is good for your users. You must have a flexible logging system to catch these exceptions and report this to the database or ip port: or whatever you decide.

Essentially, you need to think about separation of problems if the problem is related to a data problem or a logical problem with which it should be handled accordingly.

-2
source

Source: https://habr.com/ru/post/1749973/


All Articles