• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

exceptions

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic