• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to handle RemoteException?

 
Peter Aarum
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

Any thoughts regarding extending RemoteException (or IOEx..) with my own ServiceException?

Is there something wrong with this aproach?

Cheers!
Peter
 
Roel De Nijs
Sheriff
Posts: 10409
133
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you gonna extend RemoteException with your own ServiceException As far as I know RemoteException is already an existing exception, and Java does not support multiple inheritance, so I'm quiet confused about your question
 
Peter Aarum
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class ServiceException extends RemoteException { is what i mean.

/P
 
Roel De Nijs
Sheriff
Posts: 10409
133
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So actually your ServiceException is extending RemoteException and not in the other direction

I don't think that's a good idea. Your ServiceException is-NOT-a RemoteException, so you should not use RemoteException from a design perspective.

I will describe my approach in exception handling: I created a specific service exception for each possible exception that could occur (room already booked, no rooms found,...). In my controller (at the client) I catch all the possible service exceptions (depending on the invoked method) AND a RemoteException. I rethrow a specific client-side exception (which wraps the (original) caught exception with an appropriate message for the user. So in my view I just have to catch this specific client-side exception and I can simply show the message to the user (and also log the exception, when needed).

Hope it is helpful!
Kind regards,
Roel
 
Peter Aarum
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Roel for the reply
Glad we cleared the who is extending who issue
hmm isnt this kinda like wrapping a FileNotFoundException with say a DataAccessException in the db-layer? Ofcourse I dont extend it but ... anyway.


/P
 
Roel De Nijs
Sheriff
Posts: 10409
133
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's the same principle. So you are hiding the implementation details, which is a thing from a design perspective. Because you can replace the existing implementation (using a database file) with a complete new implementation (using a RDBMS for example) without having to change anything besides your implementation class
 
Peter Aarum
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But its not good in the service-layer?
BTW I havent done this extending yet but the idea came to me when reading the other topic about RMI vs Socket.
 
Roel De Nijs
Sheriff
Posts: 10409
133
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you could do it in the service layer (as you described in a previous post), bu my remark still stands: you'll need inheritance, although your ServiceException is-NOT-a RemoteException, so from a design perspective it's not a good thing to do. But it's your choice (and don't forget to document it).
 
Peter Aarum
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Roel!

I hear you and see your points. I will think more of this.

Have a great day!

/P
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic