If I re-throw SQLException on the view level, my view layer will not only be associated with the DAO layer, will it?
This is absolutely correct.
Is it wrong to throw a new exception, so the view only depends on the level of the level below, and not two?
That's right. If your DAO level cannot handle the exception coming from SQL, it should catch it, make as much sense as possible and throw its own exception.
Consider an example: let your DAO layer allow you to add new elements where a specific attribute must be unique. The SQL level can have a unique constraint or a unique index to enforce this constraint at the RDBMS level. If the caller of your DAO layer tries to save an object that violates the uniqueness constraint, an SQL exception will be thrown. If you allow this exception to apply to callers, most likely they will not know what to do with it, and perhaps even show them to end users:
ORA-00001: unique constraint (UxPatient_rec_soc) violated
This solution is very bad, but the alternative to try and understand it on the client is even more fragile.
Your DAO should catch the exception, decide what it means to the caller, and throw its own exception. This way you can change your implementation regardless of your caller.
General Note: When considering throwing / re-throwing exceptions, performance considerations should be considered, since exceptions should only be thrown in rare exceptional situations. The clarity of your interfaces is much more important.
source share