Consider this scenario: I have 3-layer app, when the user click on the button the button event handler calls a method in biz layer that do whatever with data my button event handler supply and then pass that data to the data Access layer which sends them to the backend database. The question is where to put the try catch? In the data layer, in biz layer, in presentation layer or maybe put it around all of them? What the best strategy to represent exception handling as in this scenario?
We follow
Do not catch exceptions if you do not know what to do with it.
We never handle any exceptions which we cannot handle or default. It gets bubbled up and we handle it at the application level.
Say if you can default a value, for a businesss object, then you can handle it in the business layer.
definitely put a try catch closest to the user -- because in that location you can translate it into something meaningful for your user.
Deeper try catches could only be needed if you intend to do something with them -- for example, handle the exception, or perhaps log and rethrow the exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With