Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Exceptions & RMI Conflict

 
Javini Javono
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Here's another idea.
I've seen in some posts about possible solutions to the
exceptions Data throws, and how in another context
it needs to throw RMI exceptions, and how this
creates problems (though not necessarily unsolvable
ones).
Here is one possible solution idea:
Even though Data implements DBMain
and any method in DBMain
throws some exception,
it is not required that any corresponding method
in Data need throw any exceptions: i.e.,
public void read(int recNo) /* throws no exceptions */ {
}
You would then handle exceptions as talked about
in this link:
http://www.coderanch.com/t/184888/java-developer-SCJD/certification/NX-MyException-Class
and get back all the exceptions you could desire.
Please keep in mind that these are solution ideas,
as I circle around before making my preliminary
decisions prior to initial implementation; that is,
I have not yet tried these out in practice myself,
but I'm about to.
Legal Note: I don't think it is "illegal" (from Sun's
testing standpoint) for a method
in Data not to throw an exception; the compiler
ensures that whatever is thrown must be an
instance of, let's say, RecordNotFoundException,
but the compiler certainly will not complain
if the method throws no exceptions whatsoever.
thanks,
Javini Javono
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Javini,
If the interface declares that it throws an exception, then your implementing method must also declare that it throws the exception (even if it does not actually throw it).
Regards, Andrew
 
Javini Javono
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andrew Monkhouse:
Hi Javini,
If the interface declares that it throws an exception, then your implementing method must also declare that it throws the exception (even if it does not actually throw it).
Regards, Andrew

Hi,
I did a couple tests, and when DBMain's methods throw a RecordNotFoundException which
extends Exception, Data's methods did not need to throw any exceptions to compile.
Perhaps I'm doing something wrong?
Nevertheless, the above idea I wrote about is logically flawed at a higher level:
that is, the RMI exception must be declared by the methods so requiring it.
Thanks,
Javini Javono
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic