File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to handle RemoteException? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "How to handle RemoteException?" Watch "How to handle RemoteException?" New topic
Author

How to handle RemoteException?

Peter Aarum
Ranch Hand

Joined: Jan 14, 2010
Posts: 44
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
Bartender

Joined: Jul 19, 2004
Posts: 5216
    
  12

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


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Peter Aarum
Ranch Hand

Joined: Jan 14, 2010
Posts: 44
public class ServiceException extends RemoteException { is what i mean.

/P
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5216
    
  12

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

Joined: Jan 14, 2010
Posts: 44
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
Bartender

Joined: Jul 19, 2004
Posts: 5216
    
  12

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

Joined: Jan 14, 2010
Posts: 44
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
Bartender

Joined: Jul 19, 2004
Posts: 5216
    
  12

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

Joined: Jan 14, 2010
Posts: 44
Thanks Roel!

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

Have a great day!

/P
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to handle RemoteException?