I want to implement rmi and get this error
test/PatientGui.java [151:1] getEnToonData() in test.PatientGui cannot
override getEnToonData() in test.ViewModel; overridden method does not throw
java.rmi.RemoteException
Public class PatientGui
void getEnToonData() throws java.rmi.RemoteException
{
}
Public Class ViewModel
void getEnToonData()
{
System.out.println("Moet nog gemaakt worden in de sub-class");
}
If i remove the throws java.rmi.RemoteException, the compiler tells me it
should be thrown.
How can i solve this?
Thanks
Daniel
Fred L. Kleinschmidt - 17 Jun 2005 15:50 GMT
> I want to implement rmi and get this error
>
[quoted text clipped - 22 lines]
>
> Daniel
Show us how you REALLY coded this, not the incomplete typing above (as
you show it here, there is no overridden method, since neither class
extends the other). As it is, we can only guess what mistakes you might
have made.

Signature
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225
Dale King - 18 Jun 2005 02:42 GMT
> I want to implement rmi and get this error
>
[quoted text clipped - 19 lines]
>
> How can i solve this?
The issue is not specific to RemoteException, but with your design not
allowing for the possibility of unexpected behavior. Your ViewModel says
that it cannot throw a checked exception which RemoteException is and
that it must return data. What you need to think about is what is
supposed to happen if a subclass of ViewModel encounters a failure and
can't actually get the EnToonData?
Should it ignore any errors and return data anyway? This is usually not
desired, but if so you would have to catch the exception in the subclass
and return something.
Should it throw an unchecked (aka run-time) exception? In this case you
would catch the exception in the subclass and throw a runtime exception
(one that does not extend Exception). If you are using 1.4 or later you
would probably want to use the chained exception facility to point to
the RemoteException (see
<http://java.sun.com/j2se/1.5.0/docs/guide/lang/chained-exceptions.html>).
The most likely scenario is that your design should account for the fact
that this method can throw excpeptions and declare that the method in
ViewModel can throw a checked exception that users of that method have
to handle. This should not be RemoteException because that ties you to
RMI. You probably want to make your own exception class and declare that
it throws that. Your subclass would then do like the previous case
except that you use this exception class rather than the runtime exception.

Signature
Dale King