This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

exceptions

 
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
 
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?
 
Bartender
Posts: 9559
12
Mac OS X Linux 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.
 
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!