I am writing a middle layer that bridges a server layer with a presentation layer. The server layer throws exceptions that have meaningful information to the problem at hand (and to the presentation layer).
If I catch those exceptions, the only thing I could do is rethrow them as one of my exceptions. I don't add any value to the error message. I'm not sure what is considered proper protocol here. I am supposed to shield the presentation away from the server, but if I let their exceptions go through, then the presentation has to import the servers exception class (something they don't do), but it seems silly for me to catch the server exception only to wrap it in one of my exceptions and throw it.
I imagine this must be a common issue. How do you bubble up exceptions through all the middle layers when the 2 modules that either provide or need the info aren't supposed to know about each other?
I set up an Observer - Observable relationship between the presentation layer and the middle layer. This provides a level of indirection so that changes to either layer will not effect the other layers, nor do they need to import anything unusual (i.e. server-side exception classes). I usually refine this relationship to consist of custom exception, event and listener classes so the objects being thrown around are a little more meaningful.
Originally posted by N Goldsmith: but it seems silly for me to catch the server exception only to wrap it in one of my exceptions and throw it.
It actually makes perfect sense to do it like that. I would just add that you can either chain the exceptions (which is what you describe) or just construct and throw your exceptions as the reaction to an incomming exception if there is no info the client can use.