Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Handling in 3 layered architecture

How do I implement error handling elegantly? For example, my data access layer can potentially throw 2 types of errors: 1) not authorized access, in which case the page should hide everything and just show the error message 2) errors that inform the user that something like this already exists in the database (say name not unique - for example), and in this case I wouldn't want to hide everything.

EDITED:

As a result of some comments here I devised that I should create derived specialized exception types, such as NotAuthorizedException, DuplicateException, etc etc.... it's all fine and dandy, however I can see 2 problems potentially:

1) Every stored proc has a return field p_error where it contains an error message. Upon getting the data from DB, I need to check this field to see what type of an error has been returned, so I can throw an appropriate exceptions. So, I still need to store my error types/error messages somewhere.....In other words, how do I should the exact message to the user (at certain times I need to) w/o checking the p_error field first. WHich brings me back to error object. Anyone?

2) I can this potentially turning into a nightmare where the number of exceptions equals the number of error message types.

Am I missing something here?

Much thanks to everyone!

like image 650
sarsnake Avatar asked Apr 06 '09 23:04

sarsnake


People also ask

What are the three layers of error handling?

Also provides some best practices to implement error handling in the three layers of SOA i.e. orchestration, mediation and component layers.

What is error handling and its types?

Error handling refers to the response and recovery procedures from error conditions present in a software application. In other words, it is the process comprised of anticipation, detection and resolution of application errors, programming errors or communication errors.

What is difference between 3 tier and 3 layer architecture?

In simple term 3 layer architecture can implement in single machine then we can say that its is 1 tier architecture. If we implement each layer on separate machine then its called 3 tier architecture.

What is error handling in MVC?

The HandleErrorAttribute is an attribute that can be used to handle exceptions thrown by an action method or a controller. You can use it to display a custom view on a specific exception occurred in an action method or in an entire controller.


2 Answers

You should check out the exception handling block in Enterprise Library. Lots of good tips and codeware surrounding wrapping exceptions and passing them between layers.

like image 127
JP Alioto Avatar answered Oct 23 '22 13:10

JP Alioto


Where's your business layer, and why isn't it checking Authorization and integrity? The DAL is too low level to be checking those rules - if you hit a problem there, it's pretty much time to throw an exception. Your business layer or controllers can catch that exception, and display a reasonable message - but it's not something you should regularly be doing.

like image 31
Mark Brackett Avatar answered Oct 23 '22 14:10

Mark Brackett