• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RemoteException vs IOException

 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
In my ConnectionFactory interface, I have the getConnection method only throwing IOException. Is it necessary to explicitly throw RemoteException also even though it is a subclass of IOException? I'm doing the same thing on the lock method of my DataAccess interface.
Remote clients connect fine and all the public Data methods work well across the wire.
Thanks for your opinions,
Michael Morris
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have only RemoteException, but as you state RemoteException is a subclass of IOException, so therefore almost the same thing. Either you are specific or you are generic.
But if you throw an IOException and try to catch a RemoteException then Kaboom!!.

Mark
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
Thanks for the reply. I thought I might give you the reason for throwing IOException in getConnection. The Data object may not have been constructed (and in fact won't be until the first call to getConnection). Before you ask, Data is not a Singleton. Of course the lock method is similar in that it already throws IOException on an invalid record. It just seems redundant to declare both Exceptions when the more general one will suffice.

Thanks again,
Michael Morris
[ April 25, 2002: Message edited by: Michael Morris ]
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike,
I will tell you what I am doing in my code. My remote interface which has the method to return the connection object throws RemoteException. Also my remote interface which has methods defined in the Data class throw both RemoteException and DatabaseException.
I convert any exception I get on the server side to RemoteException before sending it to the client. If you look at RemoteException constructor, you can encapsulate other Throwable object in it.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sai,
That's not a bad idea. Right now I am finishing up on the server (it's taken a week longer than expected ) and am dealing mostly with exceptions that occur while booting or killing the server. The bootstrap code is in a separate class from the server GUI. The boot object is an Observable and the GUI (actually an inner class of the GUI) an Observer. Status messages (Objects) from the boot object are sent using the Observer pattern and when an exception occurs instead of String, the exception is sent which is cast back to Throwable in order to call getMessage(). I then pop up a dialogue indicating there was a problem during boot.
I will certainly look into your method in the client code.
Thanks,
Michael Morris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic