Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about DvdDatabaseImpl class in book

 
Tim Fernandez
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,

I am just wondering why only some of the DvdDatabaseImpl class methods throw the RemoteException? Shouldn't all the methods throw the RemoteException?

tia,
tim
 
Kevin Conaway
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

Without knowing the specifics of the class, I'm pretty sure that only remote methods have to throw RemoteException. Rather, those methods that are declared in the Remote interface must throw it.

Kevin
 
Tim Fernandez
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the book, this class resides in the server package which means this can be called remotely. I would assume then that all methodsw defined in this class should throw the remote exception. But apparently in the sample code some methods don't.



Originally posted by Kevin Conaway:
Hi Tim,

Without knowing the specifics of the class, I'm pretty sure that only remote methods have to throw RemoteException. Rather, those methods that are declared in the Remote interface must throw it.

Kevin
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,
I am just wondering why only some of the DvdDatabaseImpl class methods throw the RemoteException?
I am wondering why any of the DvdDatabaseImpl class methods throw the RemoteException.

I was sure that this was mentioned in the book somewhere (I remember discussions with the publisher about it nearly 18 months ago), but basically there are changes we made to our sample application just to make it different from the assignment you receive from Sun. Some of these changes made our sample application more complex (such as being able to handle both RMI and Sockets from the one application) and some made our application much simpler.

In the later category, we made the decision to have our Data class' methods throw IOException. Since you do not need to declare any child exceptions of a declared exception, we do not need to explictly state that we are throwning RemoteException.

Does that make sense?

Regards, Andrew
 
Tim Fernandez
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andrew Monkhouse:
Since you do not need to declare any child exceptions of a declared exception, we do not need to explictly state that we are throwning RemoteException.


What do you mean child exception of a declared exception?And how is it related to throwing RemoteException. Im sorry if this is such a stupid question.

thanks,
tim
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

This is not a stupid question at all. Sometimes I forget to fully explain things - I have been fortunate with the book in that the people reviewing it were very good at picking up things that werent clear. Unfortunately we may still have skipped things, and when posting here I dont have anyone doing a peer review. So if you (or anyone else) feels that I haven't explained things clearly, it is probably my fault, so please do ask for clarification.

If you look at the API for java.rmi.RemoteException, you will see a diagram showing which exceptions were extended in order to eventually create the java.rmi.RemoteException:So RemoteException extends IOException which extends Exception which extends Throwable which extends Object.

This is sometimes referred to as a tree diagram, and if you are dealing with XML you will probably get used to dealing with the root node, branches, and leaf nodes.

They are also referred as showing parent-child relationsips - this may make more sense if you can picture a tree, and then consider it as a family tree. Object is the parent of everything shown in that inheritance diagram, and only one of it's children is shown: Throwable. Throwable also has only one child shown (Exception), and so on down the tree. However it is quite possible that there may be more children than are shown - they have just been left out to make it more concise (imagine how big the diagram could get if all objects that inherited from Object (which includes every Java object) were shown). For example Throwable has more than one real child - Error and Exception. So a (slightly) more complete diagram might look like:While being more complete (and yet still a long way away from being really complete) the addition of Error and VirtualMachineError does not help in understanding RMI at all, so they are left off diagrams.

Now, if we can imagine that Object is the parent of Error and Exception, then VirtualMachineError is a child of Error, and IOException is a child of Exception. Although not normally nomenclature, VirtualMachineError and IOException would be cousins.

How does this all relate back to the original question? Because RemoteException is a child of IOException (that is, RemoteException extends IOException), and because we declare our Data class' methods to throw IOException, we do not need to declare that the methods also throw RemoteException - if the parent can be thrown then it is automatically assumed that the children can be thrown.

Did that help with the original question and/or with understanding the terms I was using?

Regards, Andrew
 
Tim Fernandez
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,

Thanks for clearing things out! I should have known that IOException is the parent of RemoteException!


again thanks,
tim
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic