• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Combining Database and Remote exception

 
Pander Musubi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Objects of Data can throw DatabaseException, but via RMI Remote exceptions are thrown. I combined these by having DatabaseException extend RemoteException and have methods catch or throw DatabaseExceptions and at the same time (when RMI is being used) also handling the RemoteExceptions.
By passing the exceptions on really easy and catch them all in one place and still see where they originate from. Is this approach been used by others? Is there any criticism on combining the exceptions like this?
Regards,
Pander
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This can work but be careful on how you use DatabaseException.
If it inherits from RemoteException then it should only be thrown
under similar situations/scenarios/contexts that a RemoteException would be thrown. Otherwise your code gets messy and will not make sense.
Now DatabaseException is its own class and thus is thrown for different
reasons than RemoteException, but you do not want to step to far outside
of the boundaries. For example you would not want to throw a RecordAlreadyBookedException in place of an IOException. Or wrap a
RecordAlreadyBookedException around an IOException and throw the
RecordAlreadyBookedException.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic