Question

I was reading up this code review questions here and tutorial by BalusC. In that I have found that exception classes are extended.

What is the need of it? I read something along the lines of client layer should not know SQLExecption but I am not sure I understand it.

Could you reason why to make specialized exceptions? What if my DAO method does not have throws and the client code is in a try-catch.?

Was it helpful?

Solution

Because DAO could be today throw SQLException tomorrow if you want to change DAO layer to write to File, it might result in FileNotFoundException, So hiding underlying stuff you show to your client what matters to them (custom business sensible Exception)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top