Occasionally, it is appropriate to translate one type of exception into another.
The data layer, for example, can profit from this technique. Here, the data layer seeks to hide almost all of its implementation details from other parts of the program. It even seeks to hide the basic persistence mechanism - whether or not a database or an ad hoc file scheme is used, for example.
However, every persistence style has specific exceptions - SQLException for databases, and IOException for files, for example. If the rest of the program is to remain truly ignorant of the persistence mechanism, then these exceptions cannot be allowed to propagate outside the data layer, and must be translated into some higher level abstraction - DataAccessException, say.
See the data exception wrapping topic for an extended example.
See Also :
No comments:
Post a Comment