• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • Last Modified:

Java RMI Exception Problem

I have a GUI which needs to pass variables to a class. If I try to make an instance of that class 'Asb asb = new Asb();'
 I get the error saying "unreported exception java.rmi.RemoteException; must be caught or declared to be thrown".
public class Asb extends UnicastRemoteObject implements Publisher,
		 Serializable
 
{
 
public Asb() throws RemoteException
     
   {
        
super();
            
     }
 
}

Open in new window

0
namsu55
Asked:
namsu55
2 Solutions
 
MicheleMarconCommented:
As you have declared, the Asb() constructor throws RemoteException.

You need to do this:

try{
Asb asb = new Asb();
//your code here
}catch (RemoteException e){
//something has gone wrong, you can put debug code or fix the problem.
System.out.println("Something bad happened!");
}
0
 
namsu55Author Commented:
Yeah that works, can you give me an example of system.out.println, where if connection is not made or not present (rmiregistry not turned on) throws an exception. From within the ABS class.
0
 
basav_comCommented:
throw(e);
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
namsu55Author Commented:
try{
Asb asb = new Asb();
//your code here
}catch (RemoteException e){
//something has gone wrong, you can put debug code or fix the problem.
System.out.println("Something bad happened!");
}
throw(e);

That doesnt work it says incompatible types.
0
 
basav_comCommented:
Actually you can declare the class throws exception:
See this example is very close to your question:
http://www.experts-exchange.com/Programming/Languages/Java/Q_20985361.html
0
 
basav_comCommented:
try{
Asb asb = new Asb();
//your code here
}catch (RemoteException e){
//something has gone wrong, you can put debug code or fix the problem.
System.out.println("Something bad happened!");
throw(e);    ---->  You messed up the brackets
}
0
 
namsu55Author Commented:
It now says what it said before : "unreported exception java.rmi.RemoteException; must be caught or declared to be thrown".
0
 
Thomas4019Commented:
I just use e.printStackTrace(); This causes it to print the Exception to the Console window.
try{
Asb asb = new Asb();
//your code here
}catch (RemoteException e){
e.printStackTrace();
}

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now