Exception Handling in 3 tier

skyman763

New member
Joined
Sep 7, 2005
Messages
4
Programming Experience
1-3
i am working on a application that is 3 tier And i want to have customized "Exception handling" the problem is that when i am in "DataAccessLayer " i.e,how can i stop continuing operation and making a userFriendly Message with "try Catch" block you know that "thrown" method doesn't make user friendly message and page.


regards
A.Doroudian
 
Handling of errors should happen as close to the source as possible. However, there should be no UI in data access layers. So, the question becomes one of design. How do you handle an error as close to the data as your can, but with out messageboxes in the DA?

Two schools of thought:
1) Everything should be a function that returns a type integer. The value fo the integer that is passed back indicates if the action was successful (generaly 0) or if there was an error. In this case, the value of the integer can be the error number, or some pre-defined number that corresponds with the error.
2) HAve a byref variable on the end of your parameters that is of type string (or integer) and indicates the success (by either blank (for a striong) or a 0 (for integer)). If there was an error, then return the Error Description (or number).

-tg
 
some we send data from inner layer

thanks for your suggestion it is very good but, some function from inner layer should return data object like datatable,how we can control to return a variable or a dataobject like datatable.

Regards
A.Doroudian
 
if an error occurs in the DataTeir (DataAccessLayer) instead of returning a dataobject (dataset) throw an exception

Friend Function (byval YadaYada)
Try
'Get Data
Catch
Throw New DataAccessException
End Try
End Function

this way in the try/catch block that the PresentationTeir or the BusinessTeir will receive the exception (error) and they can present the error to the user (or fix it and try again)

by doing it this way, all the error catching is done at the source yet the DataTeir doesnt have anything to do with the user
 
Just out of curiosity, what's the point of catching the error in the data component, only to throw it to the BL? Why not just have the error handler in the BL, and no handling in the DAL? I find it odd that it's common practice to handle the error only to raise or throw it back up to the calling layer. In my latest project, I gave up having Try...Catches in the DAL because I was only Trowing the error back up one level. Now, if there was some specific reason to catch it and truly handle it, then I can see that but if the entire error handler simply passes the buck.... what's the point?

-tg

ps: I'm not saying there's anything wrong with it, I'm just wondering what the rationalization is.
 
actually i dont know exactly why it's handled in that manor (the catching of the error in the DT (DataTeir) but to pass it to the BT (BusinessTeir) and finally for something to be done with it in the PT (PresentationTier)

it's just the way i was taught, so yea... lol
 
I know, I know... it was the way I was taught too.... and now I'm starting to question that ideaology....

-tg
 
thanks for your idea i think all of u have a similar idea that we should send param to presentation layer(UI). and there handle Error.i thought to use session
that means when An Error happened i set value for session and in each layer
check
 
Back
Top