Manoj<br />SCJP, SCJD, SCWCD, IBM WSAD.
Originally posted by Jmannu gundawar:
In the MAX's DVD project, the code listing is as follows:
public interface DBClient {
(methods decleared here do not throw RemoteExceptions)
}
Then there is another interface created for the RMI (remote) package:
public interface DVDDatabaseRemote extends Remote, DBClient {}
The class DVDDatabaseImpl in the remote package is decleared as:
public class DVDDatabaseImpl extends UnicastRemoteObject implements
DVDDatabaseRemote {
Now the DBClient methods implemented in this class throws the RemoteException, where as the methods decleared in the interface dont.
How is this possible?
Why does it not give a compile time error,as the overridden methods (methods decleared in the interface) do not throw this exception??
If I try to implement interface method in the class, I get compile time error if class's method's throw the RemoteException and Interface method is not decleared to throw that exception.
Please help.
Thanks,
Manoj
[ October 20, 2003: Message edited by: Jmannu gundawar ]
Manoj<br />SCJP, SCJD, SCWCD, IBM WSAD.
"I'm not back." - Bill Harding, Twister
Manoj<br />SCJP, SCJD, SCWCD, IBM WSAD.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
"I'm not back." - Bill Harding, Twister
Manoj<br />SCJP, SCJD, SCWCD, IBM WSAD.
Manoj<br />SCJP, SCJD, SCWCD, IBM WSAD.
"I'm not back." - Bill Harding, Twister
Manoj<br />SCJP, SCJD, SCWCD, IBM WSAD.
"I'm not back." - Bill Harding, Twister
The Foo and RemoteFoo interfaces are certainly similar, but a RemoteFoo is not a Foo, and can't be, because RMI will end up requiring the RemoteFoo to be able to throw exceptions which a Foo may not throw. So, we can use a RemoteFooAdapter to convert a RemoteFoo to act like a Foo. This means you have to catch any RemoteExceptions and handle them somehow. The simplest thing I came up with is to throw a RuntimeException, though there are other strategies possible.
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
"I'm not back." - Bill Harding, Twister
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
Manoj<br />SCJP, SCJD, SCWCD, IBM WSAD.
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
"I'm not back." - Bill Harding, Twister
Manoj<br />SCJP, SCJD, SCWCD, IBM WSAD.
Originally posted by Jmannu gundawar:
And now I also know what is the bottom line(ha ha) It says:
"I have a catapult. Give me all the money, or I will fling an enormous rock at your head."
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
SCJP 1.4, SCJD, SCWCD 1.4
As I understand it we are free to generate our RecordNotFoundException, which we could make extend IOException - after all, it sounds like a type of IOException.
RemoteException also extends IOException.
Therefore we can write one adapter, DBAdapter, which throws IOException where appropriate instead of either RNFE or RemoteException. And hence both the RemoteClient and LocalClient could implement the same interface removing the need for an adapter for the remote and a separate adapter for the local (and making a nice little factory class to return a connection of the correct type).
SCJP 1.4, SCJD, SCWCD 1.4
My project doesn't declare a DuplicateKeyException. Could you really argue that DuplicateKey is an IOException.
Maybe you could
I like consistency over everything else regarding exceptions. So as I liked your reasoning about RNFE, if seemed natural to me to do the same with DuplicateKeyException. If you think that Data belongs to some broad "IO domain", it makes sense IMO that all checked exceptions thrown by Data methods would extend IOException.
findByCriteria() doesn't throw any exception, so it doesn't provide any IOException possible wrapper
If you may defend that DuplicateKeyException would be an IOException, the contrary is hard to defend : in createRecord(), throwing DuplicateKeyException because of an IOException caused by some disk failure would be misleading IMO. Same reasoning may be applied to RNFE BTW.
SCJP 1.4, SCJD, SCWCD 1.4
SCJP 1.4, SCJD, SCWCD 1.4
SCJP 1.4, SCJD, SCWCD 1.4
"I'm not back." - Bill Harding, Twister
SCJP 1.4, SCJD, SCWCD 1.4
Consider Paul's rocket mass heater. |