Reputation: 13608
I have a 3 tier win forms app, it has a UI, BLL and DAL. I'm looking to add an exception handler that throws exceptions from the DAL all the way up to the UI so the user knows what the error is. I have tried using try{} catch{} and throwing it from the DAL, but this only throws it up to the BLL and stops there. is there any way to throw it right back to the UI?
Thanks
EDIT:
CODE:
Upvotes: 0
Views: 1349
Reputation: 9027
Each layer should wrap the exception in a slightly more abstract exception.
For example, take a simple customer logon operation:
Each layer below the UI does not necessarily know the wider context of the operation which is in progress, so it's up to the layer above to provide more contextual information about what went wrong...
Maybe a better example would be a cusomer registration operation:
Upvotes: 7
Reputation: 1505
The Code provided seems to use a generic Exception to relate the error. this is probably a bad idea, as if you catch any Exceptions anywhere else, that code could easily be consuming this Exception as well when you dont expect it to.
I would specify some custom exceptions for this specific error, and specifically catch/rethrow those Exceptions. using base class Exception will just lead to confusion between different catches in different places.
Upvotes: 2