• Post Reply Bookmark Topic Watch Topic
  • New Topic

exceptions  RSS feed

 
N Goldsmith
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

thank you
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just print it on the console. if you dont want that too then just catch it and do nothing.

how is it?
 
Joe Ess
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Petr Blahos
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


Hi N,

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.

Best regards,
Petr
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!