try{}catch(){} with RMI

N

Nancy.Nicole

Everytime I try to connect with the server via RMI I get stuck in
catch().

try
{
GarageServerImpl g = new GarageServerImpl();
Naming.rebind("Serve", g); // sets the handle
System.out.println("GarageServer started and " +
"awaiting connections.");
}
catch (RemoteException er)
{
System.out.println(
"Exception in GarageServer.main: " + er);
}
catch (Exception err)
{
System.out.println(
"Exception occurred: " + err);
}
}

Help? I don't know how to fix...
 
O

Oliver Wong

Everytime I try to connect with the server via RMI I get stuck in
catch().

try
{
GarageServerImpl g = new GarageServerImpl();
Naming.rebind("Serve", g); // sets the handle
System.out.println("GarageServer started and " +
"awaiting connections.");
}
catch (RemoteException er)
{
System.out.println(
"Exception in GarageServer.main: " + er);
}
catch (Exception err)
{
System.out.println(
"Exception occurred: " + err);
}
}

Help? I don't know how to fix...

If you're just going to display the exception, don't catch it at all.
Instead, throw it all the way up, and the JVM will eventually catch and
display the exception for you, with more detailed information (such as a
stack trace).

Once you have the stack trace, post it here. See
http://riters.com/JINX/index.cgi/Su...estions_20on_20Newsgroups#RepeatErrorsExactly

- Oliver
 
E

Eric Sosman

Everytime I try to connect with the server via RMI I get stuck in
catch().

try
{
GarageServerImpl g = new GarageServerImpl();
Naming.rebind("Serve", g); // sets the handle
System.out.println("GarageServer started and " +
"awaiting connections.");
}
catch (RemoteException er)
{
System.out.println(
"Exception in GarageServer.main: " + er);
}
catch (Exception err)
{
System.out.println(
"Exception occurred: " + err);
}
}

Help? I don't know how to fix...

I don't know what's wrong, but here's a suggestion: Each
of those Exception objects carries a lot of information about
the exact nature of the error and where it occurred -- and
you're throwing most of it away. (And you've kept what little
remains hidden from the rest of us ...)

Discard those System.out.println() calls and use the
Exception objects' printStackTrace() methods instead, and
you're likely to learn lots more about the circumstances
of the problem.
 
T

Thomas Fritsch

Everytime I try to connect with the server via RMI I get stuck in
catch().

try
{
GarageServerImpl g = new GarageServerImpl();
Naming.rebind("Serve", g); // sets the handle
System.out.println("GarageServer started and " +
"awaiting connections.");
}
catch (RemoteException er)
{
System.out.println(
"Exception in GarageServer.main: " + er);
}
catch (Exception err)
{
System.out.println(
"Exception occurred: " + err);
}
}

Help? I don't know how to fix...
You can declare your main method with a throws-clause:

public static void main(String args[]) throws Exception
{
GarageServerImpl g = new GarageServerImpl();
Naming.rebind("Serve", g); // sets the handle
System.out.println("GarageServer started and " +
"awaiting connections.");
}

This has two advantages: You don't need any try/catch at all,
and in case of exception the JVM will print the stack trace.
 
N

Nancy.Nicole

You can declare your main method with a throws-clause:

public static void main(String args[]) throws Exception
{
GarageServerImpl g = new GarageServerImpl();
Naming.rebind("Serve", g); // sets the handle
System.out.println("GarageServer started and " +
"awaiting connections.");
}

This has two advantages: You don't need any try/catch at all,
and in case of exception the JVM will print the stack trace.


Okay, here's the problem with that:

All of this happens when the user clicks "Submit", which means
actionPerformed calls my getQuote() method which is what uses the
try{}catch(){}. actionPerformed cannot throw an exception (or so that
is what the command prompt declares).

I can't think of another way to get around it. Ideas?
 
O

Oliver Wong

You can declare your main method with a throws-clause:

public static void main(String args[]) throws Exception
{
GarageServerImpl g = new GarageServerImpl();
Naming.rebind("Serve", g); // sets the handle
System.out.println("GarageServer started and " +
"awaiting connections.");
}

This has two advantages: You don't need any try/catch at all,
and in case of exception the JVM will print the stack trace.


Okay, here's the problem with that:

All of this happens when the user clicks "Submit", which means
actionPerformed calls my getQuote() method which is what uses the
try{}catch(){}. actionPerformed cannot throw an exception (or so that
is what the command prompt declares).

I can't think of another way to get around it. Ideas?

For debugging purposes, catch and rethrow as an error. E.g.

public yourMethod() {
try {
/*whatever*/
} catch (NameOfTheException e) {
throw new Error(e);
}
}

Once you find out more information about the exception, you can figure
out how to handle it properly, in which case you'd replace the "throw new
Error(e)" code with code that actually handles the error.

- Oliver
 
N

Nancy.Nicole

Once you find out more information about the exception, you can figure
out how to handle it properly, in which case you'd replace the "throw new
Error(e)" code with code that actually handles the error.

- Oliver


Okay, sorry, the server I'm using is secure and I was trying a port
that had not yet been set to forward to the server. Obviously I don't
know anything about netwoking. Thanks for all the help, guys!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

RMI Objects Help 7
Error with server 3
Java RMI questions and MyEclipse 8
RMI & connection refused 10
RMI newbie 1
JAVA RMI PROBLEM 0
java rmi error 1
ClassNotFoundException on Core Java 2 RMI example 3

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top