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.?

有帮助吗?

解决方案

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)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top