title: Error Handling in 3 layered architecture
body: <p>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.</p>
  
  <p>EDITED:</p>
  
  <p>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:</p>
  
  <p>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?</p>
  
  <p>2) I can this potentially turning into a nightmare where the number of exceptions equals the number of error message types.</p>
  
  <p>Am I missing something here?</p>
  
  <p>Much thanks to everyone!</p>